Jump to content

User:Guywan/Scripts/ConfirmLogout.js

From Wikipedia, the free encyclopedia
This is an old revision of this page, as edited by Guywan (talk | contribs) at 18:33, 21 March 2020. 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.
$(() =>
{
    var logout = $("#pt-logout a")[0];
    if(!logout) return;
    
    var new_logout = document.createElement("a");
    new_logout.innerText = logout.innerText;
    logout.insertAdjacentElement("afterend", new_logout);
    logout.remove();
    
    document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", "<style>#use_conlog button { margin: 0 0.2em; background:transparent; border:0.2em solid white; border-radius: 9em; padding: 0 0.7em; box-sizing: border-box; color: inherit; font-weight: inherit; } #use_conlog button:active { background:rgba(255,255,255,0.6)}</style>");
    document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", "<div id='use_conlog'></div>");
    
    var conlog = document.getElementById("use_conlog");
    
    new_logout.addEventListener("click", event =>
    {
        if(conlog.lastChild)
        {
        	console.log("Used");
        	
            var previous_conlog = conlog.lastChild;
            previous_conlog.style.transform = "translateY(-130%)";
            setTimeout(() => { previous_conlog.remove(); }, 500);
        }

        conlog.insertAdjacentHTML("beforeend",
            "<div onclick='this.style.transform = \"translateY(-130%)\";setTimeout(function(){this.remove()}.bind(this), 500);' style='" +
            "position:fixed; top:0; left:0; right:0; margin: 0 0 auto 0; height: auto; line-height: 1.4em; " +
            "padding: 0.6em 2em; opacity: 1; text-align: center; z-index: 9999; font-size: 86%; box-shadow: 0 2px 5px rgba(0,0,0,0.2); " +
            "font-weight: bold; transform: translateY(-130%); transition: all 0.2s;" +
            "background: #EEE; color: #000; border: 2px solid #00F;'>" +
            "<div style='margin-bottom: 0.5em;'>You clicked on a log-out link. Do you want to continue?</div>" +
            "<div><button style='border: 2px solid #00F; color: #000'>No</button>" +
            "<button style='border: 2px solid #00F; color: #000' onclick='window.location=\"/wiki/special:logout\"'>Log out</button></div></div>"
        );

        var notice_element = conlog.lastChild;

        setTimeout(() => { notice_element.style.transform = "translateY(0%)"; }, 10);
        
        event.preventDefault();
        event.stopPropagation();
    });
});