User:Evad37/POST to Trello.js

/* Creates a Trello card from a page section. Based on the bookmarklet described at https://trello.com/add-card */ $( function($) {

// Check page is an Signpost page var thispage = mw.config.get( 'wgPageName' ); if ( !(thispage.includes("Wikipedia_Signpost/Newsroom/") || thispage === "Wikipedia_talk:Wikipedia_Signpost") ) { return; }

doTrelloLink = function(win,name,desc) { win.open('https://trello.com/add-card'+'?source='+win.location.host+'&mode=popup'+'&url='+encodeURIComponent(win.location.href)+(name?'&name='+encodeURIComponent(name):)+(desc?'&desc='+encodeURIComponent(desc):),'add-trello-card','width=500,height=600,left='+(win.screenX+(win.outerWidth-500)/2)+',top='+(win.screenY+(win.outerHeight-740)/2)); };

var section_url = []; var section_header = [];

// For each level 2 or 3 section (TODO: only those with an edit link, i.e. not articles or drafts), add link next to edit $("h2 > span.mw-headline, h4 > span.mw-headline").each(function(i) {

section_header[i] = $(":first-child", this).text; if (!section_header[i]) {									// section header wasn't a link section_header[i] = $(this).text; }

section_url[i] = "https:" + mw.config.get('wgServer') + mw.config.get('wgArticlePath').replace('$1', thispage) + "#" + $(this).attr("id"); $(this).append( " [Send to Trello] " ); });

$(".addToTrello").click( function(e){	e.preventDefault;	ii = $(this).attr("id").slice(7);	doTrelloLink(window, section_header[ii], section_url[ii]); }); });