Jump to content

User:BoxOfNotes/sugarcube.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by BoxOfNotes (talk | contribs) at 08:48, 20 August 2022 (v0.1). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.
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.
// Cookie functions
function setCookie(name,value,days) {
    var expires = "";
    if (days) {
        var date = new Date();
        date.setTime(date.getTime() + (days*24*60*60*1000));
        expires = "; expires=" + date.toUTCString();
    }
    document.cookie = name + "=" + (value || "")  + expires + "; path=/";
}
function getCookie(name) {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1,c.length);
        if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}
function eraseCookie(name) {   
    document.cookie = name +'=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
}

// Setup
sugarcubeEnabled = {
    "tools":true,
    "noSiteSub":true,
}

// Special:Sugarcube page
if(mw.config.get("wgPageName") == "Special:Sugarcube") {
    $("#firstHeading").text("sugarcube Preferences")
    $("#mw-content-text").html(`
<h2>Coming soon</h2>
`)
}

// Special:Sugarcube button in personal menu
$(`
<li id="sugarcube-button" class="mw-list-item">
    <a href="https://en.wikipedia.org/wiki/Special:Sugarcube" onclick="sugarcubeSpecial()" title="Your sugarcube preferences">
        <span>sugarcube</span>
    </a>
</li>
`).insertBefore("#pt-betafeatures")

// FEATURES

// tools
if(sugarcubeEnabled["tools"] == true) {
    $(`
<div id="sugarcube-tools" style="position:absolute;left:180px;top:12px;font-size:14px">
    Tools:
    <a onclick="sugarcubeToolsWiki">Wiki</a>,
    <a onclick="sugarcubeToolsPage">Page</a>
</div>
`).insertBefore("#p-personal");
}

// noSiteSub
if(sugarcubeEnabled["noSiteSub"] == true) {
    $("#siteSub").remove()
}