User:Closingbracket/autoopen.js

function openDiffs { const toOpen = []; for (const child of document.getElementsByClassName("mw-changeslist")[0].children[3].children) { try { if (child.tagName.toLowerCase == "div") break; if (child.classList.contains("mw-tag-mw-reverted")) continue; toOpen.push(child.querySelector("a.mw-changeslist-diff").href); } catch (e) { console.warn(`[AutoOpen] ${ e.message }`); }	}	toOpen.reverse.forEach((link) => window.open(link)); }

function initDiffView { if (document.getElementById("firstHeading").innerText.startsWith("Talk:")) { const style = document.createElement("style"); style.innerText = ` #firstHeading::after { content: "This is a talk page!"; font-size: xxx-large; font-family: sans-serif; color: white; background: red; padding: 4px; margin: 8px; border-radius: 2px; }`;		document.head.appendChild(style); } }

function init { const button = document.createElement("span"); button.setAttribute("class", "oo-ui-widget oo-ui-widget-enabled oo-ui-toggleWidget oo-ui-toggleWidget-off oo-ui-buttonElement oo-ui-buttonElement-framed oo-ui-labelElement oo-ui-toggleButtonWidget oo-ui-iconElement"); button.setAttribute("aria-disabled", "false"); button.innerHTML = ` View new `; button.children[0].onclick = => openDiffs; (async => {		const sleep = (ms) => new Promise((res) => setTimeout( => res, ms));		let container = document.getElementsByClassName("mw-rcfilters-ui-filterWrapperWidget-bottom")[0];		while (!container) {			await sleep(500);			container = document.getElementsByClassName("mw-rcfilters-ui-filterWrapperWidget-bottom")[0];		}		container.insertBefore(button, container.children[1]);	}); }

if (location.pathname.endsWith("Special:RecentChanges")) init; else if (location.pathname.endsWith("index.php")) initDiffView;