Jump to content

User:Themeparkgc/vector.js

From Wikipedia, the free encyclopedia
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.
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.
// <nowiki>
importScript('User:Ohconfucius/script/MOSNUM dates.js');  //Dates
importScript("User:GregU/dashes.js"); //Dashes
importScript('MediaWiki:LinkFixr.js'); //Link fixr
importScript('User:Ohconfucius/script/EngvarB.js');  //ENGVAR
importScript('User:AWeenieMan/furme.js'); //FUR Me
importScript('User:AzaToth/morebits.js');
importScript('User:Shubinator/DYKcheck.js'); //DYKcheck tool
importScript('User:Porchcorpter/rollback.js'); //Rollback extension
importScript('User:Splarka/ajaxfilemove.js');//File mover script
importScript('User:Ucucha/duplinks.js'); // [[User:Ucucha/duplinks]]

//RefToolbar - custom dialogs
$('head').one('reftoolbarbase', function() {
   CiteTB.UserOptions['autodate fields'] = ['date', 'accessdate', 'archivedate', 'fdate', 'gdate', 'pubdate', 'pridate'];
   CiteTB.UserOptions['months'] = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];

   new citeTemplate('cite RCDB', 'RCDB',
   [ // Basic fields
      {"field": "coaster_name", "label": "Coaster name"},
      {"field": "location"}, 
      {"field": "rcdb_number", "label": "RCDB number"},
      {"field": "accessdate", "label": "Access date"},
      {"field": "url", "label": "URL"}
   ],
   [ // Expanded fields
   ]);

   new citeTemplate('Parkz', 'Parkz',
   [ // Basic fields
      {"field": "ride_name", "label": "Ride name"},
      {"field": "location"}, 
      {"field": "parkz_number", "label": "Parkz Number"},
      {"field": "accessdate", "label": "Access date"}
   ],
   [ // Expanded fields
   ]);

   new citeTemplate('TV Tonight', 'TV Tonight',
   [ // Basic fields
      {"field": "title", "label": "Title"},
      {"field": "url", "label": "URL"}, 
      {"field": "date", "label": "Date"},
      {"field": "accessdate", "label": "Access date"}
   ],
   [ // Expanded fields
      {"field": "archivedate", "label": "Archive date"},
      {"field": "archiveurl", "label": "Archive URL"}
   ]);

   new citeTemplate('Cite press release', 'press release',
   [ // Basic fields
      {"field": "title"},
      {"field": "url"}, 
      {"field": "accessdate"},
      {"field": "date"},
      {"field": "publisher"}
   ],
   [ // Expanded fields
      {"field": "archivedate"},
      {"field": "archiveurl"}
   ]);

   new citeTemplate('Cite interview', 'interview',
   [ // Basic fields
      {"field": "last"},
      {"field": "first"}, 
      {"field": "title"},
      {"field": "url"}, 
      {"field": "accessdate"},
      {"field": "date"},
      {"field": "program"},
      {"field": "interviewer"}
   ],
   [ // Expanded fields
   ]);

   new citeTemplate('Cite patent', 'patent',
   [ // Basic fields
      {"field": "country"},
      {"field": "number"}, 
      {"field": "title"}, 
      {"field": "status"},
      {"field": "pubdate", "label": "Publication date"},
      {"field": "gdate", "label": "Grant date"},
      {"field": "fdate", "label": "Filing date"},
      {"field": "assign1", "label": "Assignee 1"},
      {"field": "invent1", "label": "Inventor 1"},
      {"field": "invent2", "label": "Inventor 2"}
   ],
   [ // Expanded fields
      {"field": "invent3", "label": "Inventor 3"},
      {"field": "invent4", "label": "Inventor 4"},
      {"field": "assign2", "label": "Assignee 2"},
   ]);
});

//Article traffic
function getTrafficURL() {
   var now = new Date();
   var month = now.getMonth() + 1;
   var monthLong;
   if (month < 10) {
      monthLong = "0" + month;
   } else {
      monthLong = month;
   }
   var year = now.getFullYear();
   return 'http://stats.grok.se/en/' + year + monthLong + '/' + encodeURIComponent(wgTitle);
}

//AUTOTAG SCRIPT
$(function() {
    if (wgNamespaceNumber == 1) {//Talk
        mw.util.addPortletLink("p-tb", "javascript:projectsTag()", 'Project tagging');
    } else if (wgNamespaceNumber == 14) {//Category
        mw.util.addPortletLink("p-tb", "javascript:catmainTag()", '{' + '{Catmain}}');
    } else if (wgNamespaceNumber == 0) {//Article
        mw.util.addPortletLink("p-tb", "javascript:hatnoteTag()", 'Add hatnote');
        mw.util.addPortletLink("p-tb", "javascript:toolbox()", 'Article toolbox');
    } else if (wgNamespaceNumber == 6) {//File
        mw.util.addPortletLink("p-tb", "javascript:thumbnailImage()", 'Load thumbnail');
        mw.util.addPortletLink('p-tb','http://toolserver.org/~magnus/commonshelper.php?interface=en&image=' + encodeURIComponent(wgTitle) + '&reallydirectupload=1&remove_categories=1&commonsense=0&lang=en&username=' + encodeURIComponent(wgUserName) + '&tusc_user=' + encodeURIComponent(wgUserName),'Move to Commons','','Move to Commons');
    } else if (wgNamespaceNumber == 10) {//Template
        mw.util.addPortletLink("p-tb", "javascript:hlistConvert()", 'Convert to hlist');
    } else if (wgCanonicalNamespace == "User" || wgCanonicalNamespace == "User_talk") {
        mw.util.addPortletLink("p-tb", "javascript:toolbox_user()", 'User toolbox');
    }
    if (location.href.indexOf("&section=new")!=-1&&document.getElementById('wpTextbox1')!=null&&wgNamespaceNumber==6) {
        document.getElementById('wpSave').click();
    } else if(location.href.indexOf("&autotag=")!=-1&&document.getElementById('wpTextbox1')!=null) {
        var x=decodeURIComponent(location.href.split("&autotag=")[1]);
        document.getElementById('wpTextbox1').value = x + "\n" + document.getElementById('wpTextbox1').value;
        document.getElementById('wpSummary').value = "Adding " + x + " using [[User:Themeparkgc/vector.js|script]]";
        document.getElementById('wpSave').click();
    } else if(location.href.indexOf("&hlist=")!=-1&&document.getElementById('wpTextbox1')!=null) {
        var content = document.getElementById('wpTextbox1').value;
        content = replaceAll(content, "  ", " ");
        content = replaceAll(content, "   ", " ");
        content = replaceAll(content, "•", "\n*");
        content = replaceAll(content, "{{·}}", "\n*");
        content = replaceAll(content, "{{•}}", "\n*");
        content = replaceAll(content, "{{·w}}", "\n*");
        content = replaceAll(content, "{{!}}", "\n*");
        content = replaceAll(content, "{" + "{Navbox","{" + "{Navbox\n|listclass=hlist\n|belowclass=hlist");
        content = replaceAll(content, "{" + "{navbox","{" + "{Navbox\n|listclass=hlist\n|belowclass=hlist");
        for(i=0;i<20;i++) {
            content = content.replace("list" + i + " =", "list" + i + " =\n*");
            content = content.replace("list" + i + "=", "list" + i + "=\n*");
        }
        content = content.replace("below =", "below =\n*");
        content = content.replace("below=", "below=\n*");
        document.getElementById('wpTextbox1').value = content;
        document.getElementById('wpSummary').value = "convert to [[WP:HLIST|hlist]] using [[User:Themeparkgc/vector.js|script]]";
        document.getElementById('wpPreview').click();
        //document.getElementById('wpSave').click();
    }
});

function replaceAll(txt, replace, with_this) {
  return txt.replace(new RegExp(replace, 'g'),with_this);
}

function catmainTag() {
    var x=prompt("Tagging for {" + "{Catmain}}. Main article: ", wgTitle);
    if (x==null) return;
    x = "{" + "{Catmain|" + x + "}}";
    location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&autotag=" + encodeURIComponent(x);
}

function hatnoteTag() {
    var str;
    var x=prompt("Add hatnote. Template name (without braces): ", "");
    if (x==""|x==null) return;
    var y=prompt("{" + "{" + x + "}} parameter (leave blank for no parameter): ", "");
    if (y==""|y==null) str = "{" + "{" + x + "}}";
    else str = "{" + "{" + x + "|" + y + "}}";
    location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&autotag=" + encodeURIComponent(str);
}

function hlistConvert() {
    location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&hlist=true";
}

function projectsTag() {
    var projects = 0;
    var str = "";
    var classRating = prompt("Please enter a class rating for the article:", "");
    if (classRating) {
        var response = prompt("Please enter an importance rating for WikiProject Amusement Parks:", "");
        if (response) {
            str += "{" + "{WikiProject Amusement Parks|class=" + classRating + "|importance=" + response;
            projects++;
            var response = prompt("Please enter an importance rating for the roller coaster task force:", "");
            if (response) {
                str += "|coaster=yes|coaster-importance=" + response + "}}\n";
            } else {
                str += "}}\n";
            }
        }
        response = prompt("Please enter an importance rating for WikiProject Australia:", "");
        if (response) {
            str += "{" + "{WikiProject Australia|class=" + classRating + "|importance=" + response + "}}\n";
            projects++;
        }
        if (str != "") {
            if (projects > 1) {
                str = "{" + "{WikiProjectBannerShell|1=\n" + str + "}}\n"
            }
            str = "{" + "{Talk header}}\n" + str;
            location.href=mw.config.get('wgServer')+mw.config.get('wgScript')+"?title=" + encodeURIComponent(mw.config.get('wgPageName')) + "&action=edit&autotag=" + encodeURIComponent(str);
        }
    }
}

function toolbox() {
    document.getElementById('bodyContent').innerHTML = '<div style="background-color:#F9F9F9;border:1px solid #AAAAAA;padding:5px;width:220px;border-radius:10px;"><ul><li><a target="_blank" href="http://toolserver.org/%7Edispenser/cgi-bin/altviewer.py/' + encodeURIComponent(mw.config.get('wgPageName')) + '">Alt Text</a></li><li><a target="_blank" href="http://toolserver.org/%7Edispenser/cgi-bin/webreflinks.py/' + encodeURIComponent(mw.config.get('wgPageName')) + '?client=script&citeweb=on&overwrite=&limit=20&lang=en">Reflinks</a></li><li><a target="_blank" href="http://toolserver.org/~daniel/WikiSense/Contributors.php?wikilang=en&wikifam=.wikipedia.org&page=' + encodeURIComponent(mw.config.get('wgPageName')) + '&since=&until=&grouped=on&order=-edit_count&max=100&format=html">Article Contributors</a></li><li><a target="_blank" href="' + getTrafficURL() + '">Article Traffic Stats</a></li><li><a target="_blank" href="http://toolserver.org/%7Edispenser/cgi-bin/webchecklinks.py/' + encodeURIComponent(mw.config.get('wgPageName')) + '">Check Links</a></li><li><a target="_blank" href="http://toolserver.org/%7Edispenser/cgi-bin/dablinks.py/' + encodeURIComponent(mw.config.get('wgPageName')) + '">DAB links</a></li><li><a target="_blank" href="http://toolserver.org/%7Edispenser/view/Peer_reviewer#page:' + encodeURIComponent(mw.config.get('wgPageName')) + '">Peer Reviewer</a></li><li><a target="_blank" href="http://toolserver.org/%7Edispenser/cgi-bin/rdcheck.py/' + encodeURIComponent(mw.config.get('wgPageName')) + '">Redirects</a></li></ul></div>' + document.getElementById('bodyContent').innerHTML;
}

function toolbox_user() {
    document.getElementById('bodyContent').innerHTML = '<div style="background-color:#F9F9F9;border:1px solid #AAAAAA;padding:5px;width:220px;border-radius:10px;"><ul><li><a target="_blank" href="http://toolserver.org/~tparis/pages/index.php?name=' + encodeURIComponent(wgUserName) + '&namespace=0&redirects=noredirects">Article list</a></li><li><a target="_blank" href="http://toolserver.org/~tparis/pcount/index.php?name=' + encodeURIComponent(wgUserName) + '&lang=en&wiki=wikipedia">Edit count</a></li><li><a target="_blank" href="http://en.wikipedia.org/wiki/Special:Contributions/' + encodeURIComponent(wgUserName) + '">User contributions</a></li><li><a target="_blank" href="http://en.wikichecker.com/user/?t=' + encodeURIComponent(wgUserName) + '">WikiChecker</a></li></ul></div>' + document.getElementById('bodyContent').innerHTML;
}

function thumbnailImage() {
    var size = prompt("Please enter a size for the thumbnail: ", "250px");
    if (size==null) return;
    var title = wgTitle;
    title.replace(" ", "+");
    location.href="/media/wikipedia/en/thumb/5/50/" + title + "/" + size + "-" + title;
}

function seealso() {
    var myField = document.getElementById('wpTextbox1');
    if (myField) {
        myField.value = "==See also==\n* [[2013 in amusement parks]]\n\n" + myField.value;
        document.getElementById('wpSummary').value = "/* See also */ new section";
        document.getElementById('wpSave').click();
    }
}
mw.util.addPortletLink("p-tb", "javascript:seealso()", 'See also');

function coord() {
    var myField = document.getElementById('wpTextbox1');
    var input = prompt("Enter coordinates separated by commas:");
    var val = input.replace(",", "|");
    if (myField && (myField.selectionStart || myField.selectionStart == '0')) {
        myField.focus();
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos) + "|coordinates={" + "{Coord|" + val + "|display=it}}\n" + myField.value.substring(endPos, myField.value.length);
    }
    document.getElementById('wpSummary').value = "coords using [[User:Themeparkgc/vector.js|script]]";
    //document.getElementById('wpDiff').click();
}
mw.util.addPortletLink("p-tb", "javascript:coord()", 'Add coordinates');
$(function () {

    // Check if we're on the watchlist
    if (!wgCanonicalSpecialPageName || wgCanonicalSpecialPageName != "Watchlist") return;
    if (!document.forms[0] || !document.forms[0].namespace) return;

    // Unwatch links go back to watchlist with "Removing requested items from watchlist..." message
    //var query_prefix = "title="+encodeURIComponent(mw.config.get('wgPageName'))+"&action=submit&remove=1&id[]=";

    // ...or...
    // Unwatch links go to "Removed from watchlist" page
    var query_prefix = "action=unwatch&title=";

    // get list of all links in content:
    var links = document.getElementById('content').getElementsByTagName('a');

    // make a static copy of the nodelist and lose the original for speed
    // while we're at it, prune the uninteresting links from the list
    var linksCopy = new Array ();
    for (var i = 0; i < links.length; i++) {
        if (/[?&]action=history([&#]|$)/.test(links[i].href)) linksCopy.push(links[i]);
    }
    links = linksCopy;

    for (var i = 0; i < links.length; i++) {
        // create unwatch link and append it after history link
        var unwatch = document.createElement('a');
        unwatch.href = mw.config.get('wgServer') + mw.config.get('wgScriptPath') + "/index.php?" + query_prefix + encodeURIComponent(links[i].title);
        unwatch.title = "Unwatch "+links[i].title;
        unwatch.appendChild(document.createTextNode("unwatch"));
        links[i].parentNode.insertBefore(unwatch, links[i].nextSibling);

        // insert a delimiter between the two links
        var delim = links[i].previousSibling;
        delimText = (delim.nodeType == 3 ? delim.nodeValue : ""); // kluge to handle case where "diff" is unlinked
        delim = document.createTextNode(delimText.replace(/^.*diff/, ""));
        links[i].parentNode.insertBefore(delim, unwatch);
    }
});
// </nowiki>