Jump to content

User:Largoplazo/common.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.
// [[User:Lupin/popups.js]]

//importScript('User:Lupin/popups.js');

window.popupFixRedirs = true;
window.popupFixDabs = true;
window.popupAllDabsStubs = true;

importScript( 'User:Technical_13/Scripts/OneClickArchiver.js' ); // Backlink: [[User:Technical_13/Scripts/OneClickArchiver]]
mw.loader.load( '/w/index.php?title=User:Evad37/OneClickArchiver.js&action=raw&ctype=text/javascript' ); // Backlink: [[User:Evad37/OneClickArchiver.js]]
//importScript('User:Fox Wilson/delsort.js'); // Deletion sorting script [[WP:FWDS]]
importScript( 'User:Enterprisey/delsort.js' ); // Backlink: [[User:Enterprisey/delsort.js]]
importScript( 'User:Evad37/MoveToDraft.js' ); // Backlink: [[User:Evad37/MoveToDraft]]

importScript('User:Largoplazo/toplinks.js').onload = function() {
	addTopLink("pt-newpagesfeed", "NewPagesFeed", "/wiki/Special:NewPagesFeed");
	addTopLink("pt-track", "TrackThisPage", "javascript:trackThisPage();");
	addTopLink("pt-revid", "ShowRevIds", "javascript:showRevIds();");
	var namespace = mw.config.get("wgCanonicalNamespace");
	if (namespace == "User_talk") {
		addTopLink("pt-autobio", "uw-autobio", "javascript:uwAutobio();");
		addTopLink("pt-coi", "uw-coi", "javascript:uwCoi();");
		addTopLink("pt-bizlist", "uw-bizlist", "javascript:uwBizlist();");
	}
//	moveTime();
};

function moveTime() {

	setTimeout(function() { $('#pt-userpage-2')[0].after($("#utcdate")[0]); }, 1000);
}

editToken = "starting value";
function addTrackedItem( summary, content ) {
    // Get token
    $.ajax({
        url: mw.util.wikiScript( 'api' ),
        data: {
            format: 'json',
            action: 'tokens'
        },
        type: 'POST',
        success: function( data ) {
            editToken = (data.tokens.edittoken);
            $.ajax({
                url: mw.util.wikiScript( 'api' ),
                data: {
                    format: 'json',
                    action: 'edit',
                    title: 'User:' + mw.config.get('wgUserName') + '/Tracking',
                    watchlist: 'unwatch',
                    summary: summary,
                    appendtext: content,
                    token: editToken
                },
                dataType: 'json',
                type: 'POST',
                success: function( data ) {
                    if ( data && data.edit && data.edit.result == 'Success' ) {
                       alert('Done');
                    } else if ( data && data.error ) {
                        alert(editToken);
                        alert( 'Error: API returned error code "' + data.error.code + '": ' + data.error.info );
                    } else {
                        alert( 'Error: Unknown result from API.' );
                    }
                },
                error: function( xhr ) {
                    alert( 'Error: Request failed.' );
                }
            });
        }
    })
}

function trackThisPage() {
	var note = prompt("What do you want to check on this page for?");
	if (!note) return;
	var days = prompt("How many days do you want to wait before checking back?")
	if ((!days) || parseInt(days) == NaN) return;
	var title;
	if (mw.config.get('wgCanonicalNamespace') == "")
		title = mw.config.get('wgTitle');
	else
		title = mw.config.get('wgCanonicalNamespace') + ":" + mw.config.get('wgTitle');
	
	var summary = "Adding " + title;
	var today = new Date();
	var deferDate = new Date(today.getTime() + days * 86400000);
	var content = "\r\n*" + today.toDateString() + " : " + deferDate.toDateString() + " : [[" + title + "]] : " + note;
	addTrackedItem(summary, content)
}

function showRevIds() {
	$("#pagehistory li").prepend(function() { return "<small>" + $(this).attr("data-mw-revid") + "</small> "; });
}

function uwAutobio() {
		uwWarn("Creating autobiographies", "Notice: creating autobiographies", "singlenotice", "uw-autobiography");
}

function uwCoi() {
		uwWarn("Editing with a conflict of interest", "Notice: conflicts of interest", "singlenotice", "uw-coi");
}

function uwBizlist() {
		uwWarn("Listing businesses", "Warning: listing businesses", "singlewarn", "uw-bizlist");
}

function uwWarn(heading, summary, warn_type, template) {
	uw_messageData = {
		heading: heading,
		label: "",
		summary: summary,
		suppressArticleInSummary: true
	}
	
	uw_params = {
		reason: "",
		main_group: warn_type,
		sub_group: template,
		article: "",
		messageData: uw_messageData
	};

	uw_page = new Morebits.wiki.page( mw.config.get('wgPageName'), 'User talk page modification' );
	uw_page.setCallbackParameters(uw_params);
	uw_page.setFollowRedirect(true);
	uw_page.load(Twinkle.warn.callbacks.main);
	
	window.setTimeout( function() { window.location = mw.config.get("wgPageName"); }, 3000 )
}