Jump to content

User:קיפודנחש/pageCollector.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
(function() {
    function save(title, content, next)
	{
		var param = {action: 'edit', title: title, summary: 'adding ' + content, token: mw.user.tokens.get('csrfToken'), appendtext: content, format: 'json'};
		$.post(mw.util.wikiScript('api'), param, function() {
            mw.util.jsMessage(content + ' added to page ' + title);
		}); //flying blind
	}
 
	function add_button(page, caption)
	{
		var addColon = $.inArray(mw.config.get('wgNamespaceNumber'), [6,14]) + 1; //file:, category:
		var pageName = (addColon ?  ":" : "") + mw.config.get('wgPageName').replace( /_/g, " " );
		var text = '[[' +  pageName + ']]';
		var a = mw.util.addPortletLink(window.pageCollectorMenu || 'p-cactions','#',caption,'','add this page to: "' + page + '"');
		$(a).click(function() {save(page, '\n* ' + text);});
	}
 
    $(window.pagesToCollect).each(function() {add_button(this.page, this.caption);});
})();