User:FlightTime/confirm-logout.js: Difference between revisions

Content deleted Content added
Per Talk page
Try your version :P
Line 1:
// [[Category:Wikipedia scripts]]
// <nowiki>
$(() =>
{
Line 4 ⟶ 6:
if(!logout) return;
// Create new logout link.
var new_logout = document.createElement("a");
new_logout.innerText = logout.innerText;
// Insert new logout link and remove old.
logout.insertAdjacentElement("afterend", new_logout);
logout.remove();
// Get user-defined styling.
document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", "<style>#use_conlog button { margin: 0 0.2em; border-radius: 9em; padding: 0 0.7em; box-sizing: border-box; font-weight: inherit; } #use_conlog button:active { background:rgba(255,255,255,0.6)}</style>");
var fw = window.us_conlog_font_weight ? window.us_conlog_font_weight : "bold";
document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", "<div id='use_conlog'></div>");
var fs = window.us_conlog_font_size ? window.us_conlog_font_size : "86%";
var bg = window.us_conlog_background ? window.us_conlog_background : "#FFDBDB";
var fg = window.us_conlog_color ? window.us_conlog_color : "#000";
var bd = window.us_conlog_border ? window.us_conlog_border : "2px solid #BB7070";
// Add styling to the page.
var conlog = document.getElementById("use_conlog");
document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin",
"<style>#use-conlog button { margin: 0 0.2em; border-radius: 9em; padding: 0 0.7em; box-sizing: border-box;" +
`font-weight: ${fw}; font-size: ${fs}; background: ${bg}; color: ${fg}; border: ${bd}}` +
"#use-conlog button:active { background:rgba(255,255,255,0.6)}</style>");
// Main grouping div for conlog elements.
document.getElementsByTagName("body")[0].insertAdjacentHTML("afterbegin", "<div id='use_conloguse-conlog'></div>");
new_logout.addEventListener("click", event =>
{
// Create the logout confirmation prompt.
var conlog = document.getElementById("use_conloguse-conlog");
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`font-weight: #EEE${fw}; colorfont-size: #000${fs}; borderbackground: 2px${bg}; solidcolor: #00F${fg}; border: ${bd}'>"` +
"<div style='margin-bottom: 0.5em;'>You clicked on a log-out link. Do you want to continue?</div>" +
"<div><button>No</button><button styleid='border: 2px solid #00F; color: #000conlog-logout'>NoLog out</button></div></div>" +
"<button style='border: 2px solid #00F; color: #000' onclick='window.___location=\"/wiki/special:logout\"'>Log out</button></div></div>"
);
// Logout handler.
document.getElementById("conlog-logout").addEventListener("click", event =>
{
new mw.Api().post(
{
"action": "logout",
"token": mw.user.tokens.get("csrfToken")
})
.fail(result => { mw.notify("Failed to log out: " + result); })
.done(() => { window.___location.href = mw.util.getUrl(mw.config.get("wgPageName")); });
});
 
// The logout confirmation prompt pops down from the top.
var notice_element = conlog.lastChild;
setTimeout(() => { notice_elementconlog.lastChild.style.transform = "translateY(0%)"; }, 10);
event.preventDefault();
Line 34 ⟶ 62:
});
});
// </nowiki>