User:Wd-Ryan/extratools.js

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
// this is for personal use but i don't mind if you use it

var extraNavbar = document.createElement("nav");
extraNavbar.id = "p-extratools";
extraNavbar.className = "vector-menu mw-portlet mw-portlet-tb vector-menu-portal portal";

extraNavbar.insertAdjacentHTML("beforeend", '<h3 id="p-extratools-label" class="vector-menu-heading "><span class="vector-menu-heading-label">Extra Tools</span></h3>' +
'<div class="vector-menu-content">' + 
'<ul class="vector-menu-content-list" id="extratools-list"></ul></div>');
document.getElementById("p-tb").insertAdjacentElement("beforebegin", extraNavbar);

// clean up navbar
document.getElementById("n-nearby-pages-title").remove();
document.getElementById("n-sitesupport").remove();
document.getElementById("n-help").remove();
document.getElementById("n-mainpage-description").remove();
document.getElementById("p-logo").style.marginBottom = "0";
document.getElementById("p-logo").style.height = "140px";
document.getElementById("p-wikibase-lexeme-lexicographical-data").querySelector("ul").id="lexeme-tools-list";


function addExtraTool(name, url, list) {
    var etList = document.getElementById(list||"extratools-list");
    etList.insertAdjacentHTML("beforeend", '<li class="mw-list-item"><a href="'+url+'"' + (url.indexOf("http")!==-1 ? ' target="_blank"' : "") + '>'+name+'</a></li>');
}

function init() {
	// if ( mw.config.get('wgNamespaceNumber') != 0 ) return ;
	// if ( mw.config.get('wgAction') != 'view' ) return ;
	// if ( mw.config.get('wbIsEditView') == false ) return ;
	// if ( mw.config.get('wgIsRedirect') == true ) return ;
	
	var etList = document.getElementById("extratools-list");
    var itemID = mw.config.get( 'wbEntityId' );
    console.log(itemID)
    if (itemID) { // entity page
        // query the first element with class wikibase-labelview but not wb-empty
        var labelElement = document.querySelector(".wikibase-labelview:not(.wb-empty)");
        if (labelElement) {
            var itemLabel = labelElement.querySelector(".wikibase-labelview-text").innerText;
        }
        else {
            var itemLabel = "";
        }

        var tempsite = document.getElementById("P856");
        if (tempsite) {
            addExtraTool("Open Website",tempsite.getElementsByClassName("external")[0].href);
        }
        addExtraTool("Jump to Presets","#quickpresets");
        

        addExtraTool("Related Items", "https://query.wikidata.org/embed.html#SELECT%20%3Fthing%20%3FthingLabel%20WHERE%20%7B%0A%20%20VALUES%20%3Faaaa%20%7Bwdt%3AP31%20wdt%3AP279%20wdt%3AP1441%20wdt%3AP1080%20wdt%3AP8345%20wdt%3AP527%20wdt%3AP170%20wdt%3AP112%20wdt%3AP138%20wdt%3AP176%20wdt%3AP800%20wdt%3AP276%20wdt%3AP361%20wdt%3AP155%20wdt%3AP156%20wdt%3AP136%20wdt%3AP178%20wdt%3AP750%20wdt%3AP86%20wdt%3AP3080%20wdt%3AP1269%20wdt%3AP941%20wdt%3AP943%20wdt%3AP287%20wdt%3AP400%20wdt%3AP306%20wdt%3AP408%20wdt%3AP106%20wdt%3AP463%20wdt%3AP2283%20wdt%3AP1535%7D%0A%20%20%3Fthing%20%3Faaaa%20wd%3A"+itemID+".%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D");
        addExtraTool("Random Instances", "https://query.wikidata.org/embed.html#SELECT%20%3Fthing%20%3FthingLabel%20WHERE%20%7B%0A%20%20SERVICE%20bd%3Asample%20%7B%0A%20%20%20%20%3Fthing%20wdt%3AP31%20wd%3A"+itemID+".%0A%20%20%20%20bd%3AserviceParam%20bd%3Asample.limit%20%22"+Math.floor(Math.random()*200+200)+"%22.%0A%20%20%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7D%0ALIMIT%20200");
        addExtraTool("Instances", "https://query.wikidata.org/embed.html#SELECT%20%3Fthing%20%3FthingLabel%20WHERE%20%7B%0A%20%20%3Fthing%20wdt%3AP31%20wd%3A"+itemID+".%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7DLIMIT 1000");
        addExtraTool("Subclasses", "https://query.wikidata.org/embed.html#SELECT%20%3Fthing%20%3FthingLabel%20WHERE%20%7B%0A%20%20%3Fthing%20wdt%3AP279%20wd%3A"+itemID+".%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22%5BAUTO_LANGUAGE%5D%2Cen%22.%20%7D%0A%7DLIMIT 1000");
        if (itemLabel) { addExtraTool("Mix'n'match","https://mix-n-match.toolforge.org/#/creation_candidates/by_ext_name/?ext_name="+(itemLabel||" ")) }
        addExtraTool("Previously Deleted","https://wd-deleted.toolforge.org/search?query="+(itemLabel||" ")+"&rows=&Search=Submit")
        // addExtraTool("Concept Cloud","https://wikidata-todo.toolforge.org/cloudy_concept.php?q="+itemID+"&lang=en");
        // addExtraTool("Reasonator","https://reasonator.toolforge.org/?q="+itemID+"&lang=en");

        var temptwitter = document.getElementById("P2002");
        if (temptwitter) {
            addExtraTool("Twitter Stats","https://socialblade.com/twitter/user/"+temptwitter.getElementsByClassName("wb-external-id")[0].innerText);
        }
        var tempyt = document.getElementById("P2397");
        if (tempyt) {
            addExtraTool("YouTube Stats","https://socialblade.com/youtube/channel/"+tempyt.getElementsByClassName("wb-external-id")[0].innerText);
        }
        var tempig = document.getElementById("P2003");
        if (tempig) {
            addExtraTool("Instagram Stats","https://socialblade.com/instagram/user/"+tempig.getElementsByClassName("wb-external-id")[0].innerText);
        }
        var temptok = document.getElementById("P7085");
        if (temptok) {
            addExtraTool("TikTok Stats","https://socialblade.com/tiktok/user/"+temptok.getElementsByClassName("wb-external-id")[0].innerText);
        }

        addExtraTool("Search Lexeme","https://ordia.toolforge.org/search?q="+itemLabel,"lexeme-tools-list");

    }
}

mw.hook( 'wikibase.entityPage.entityView.rendered' ).add( function () {
    $( init );
} );

// any page
addExtraTool("New Properties",`https://www.wikidata.org/wiki/Special:RecentChanges?hidebots=1&hidepageedits=1&hidecategorization=1&hidelog=1&namespace=120&limit=500&days=30&urlversion=2`);
addExtraTool("Property Overview","https://www.wikidata.org/wiki/Wikidata:Property_proposal/Overview");

addExtraTool("Lexeme Templates","https://lexeme-forms.toolforge.org/#en","lexeme-tools-list");

if (!mw.config.get( 'wbEntityId' )) { // not an entity page
    addExtraTool("Search Lexeme","https://ordia.toolforge.org/","lexeme-tools-list");
    addExtraTool("Mix'n'match","https://mix-n-match.toolforge.org/#/");
}