flamebyrd: (Default)
flamebyrd ([personal profile] flamebyrd) wrote in [community profile] ao3some2012-06-17 10:26 am
Entry tags:

Pinboard bookmarklet for AO3 works

I edited the default Pinboard bookmarklet (the button you put in your browser bookmarks to let you quickly add links to Pinboard) so that it will grab the tags and summary from AO3 and include those in the Pinboard tags/description.

Would anybody who uses Pinboard for their bookmarks rather than AO3 be interested in that if I posted it?

I made a generator for the bookmarklet to allow people to choose which tags to include and so on. http://random.fangirling.net/fun/ao3/bookmarklet.html

(I tried to do the same for Delicious but it doesn't look like I can pass tags to it.)

[personal profile] exclamations 2020-12-02 09:53 pm (UTC)(link)
I not sure if others might be interested in Markdown; I've never cared about the rest of the summary formatting aside from line breaks.

After further iteration, here is what I'm using now for my bookmarklet:

javascript:(function($){
var q=location.href;
var base = q.split(/[/#?]/);
if ( base[3] == "collections" ) {
	base[3] = base[5];
	base[4] = base[6];
}
q = base[0] + "\/\/" + base[2] + "\/" + base[3] + "\/" + base[4];

var p=document.title; 
var parts = p.split("-");
if ( parts[1].startsWith(" Chapter")) {
	parts[1] = parts[2]
}
p = parts[0] + "-" + parts[1];

var d="";
if(document.getSelection){ 
	d=document.getSelection();
}
if ( d=="" ) {
	d+=$(".summary blockquote.userstuff").html() ;
	d=d.replace(/<\/p><p>/g, '\n\n');
	d=d.replace(/<\/p>/g, '\n');
	d=d.replace(/<br>/g, '\n');
	d=d.replace(/<.*?>/g, '');
	d=d.replace(/&nbsp;/g, ' ');
	d=$.trim( d );
}

var options = {"wordcount_format_text":"(%words% words)","series_include_format_text":"[%series%]"};
let series = $(".work.meta .series .position").map(function() { return $.trim($( this ).text()) }).get().join( ", " );
if ( series != '' ) {
	series = options.series_include_format_text.replace('%series%', series );
	d += '\n\n' + series; 
} 

var wc = options.wordcount_format_text.replace('%words%', $(".stats dd.words").text() );
if ( d != '' ) { d += '\n' }
d += wc; 

void(open("https://pinboard.in/add?url=" + encodeURIComponent(q) + "&description=" + encodeURIComponent(d) + "&title=" + encodeURIComponent(p), "Pinboard", "toolbar=no,width=700,height=350"));})(jQuery);

Figuring out the RegExp syntax helped me get rid of most of the html code I don't care about, and my latest addition was to get rid of the occasional &nbsp;s I was seeing and strip out collections from the URL. I'm still very grateful for the base code you provided, because I never would have bothered to figure this stuff out without it.