exclamations ([personal profile] exclamations) wrote in [community profile] ao3some 2020-12-02 09:53 pm (UTC)

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.

Post a comment in response:

If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting