Created
February 8, 2025 01:10
Infinite scroll of random pages on Wiktionary and Wikiquote by creating iframes below the current scroll position as needed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Wiktionary/Wikiquote Infinite Scroll | |
// @namespace http://tampermonkey.net/ | |
// @version 1.0 | |
// @description Adds an infinite scroll of random pages to Wiktionary and Wikiquote. | |
// @author VidFerris (https://github.com/VidFerris) | |
// @match https://en.wiktionary.org/* | |
// @match https://en.wikiquote.org/* | |
// @icon https://www.google.com/s2/favicons?sz=64&domain=wiktionary.org | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
function resizeIFrames() { | |
var iframes = document.querySelectorAll("iframe"); | |
for( var i = 0; i < iframes.length; i++) { | |
heightSetter( iframes[i] ); | |
} | |
} | |
function inIframe () { | |
try { | |
if(window.self !== window.top){ | |
console.log('in iframe!') | |
}else{ | |
console.log('not in iframe!') | |
} | |
return window.self !== window.top; | |
} catch (e) { | |
return true; | |
} | |
} | |
function heightSetter(ifrm){ | |
try{ | |
ifrm.style.height = ifrm.contentWindow.document.documentElement.getElementsByClassName('mw-body')[0].scrollHeight+50 +"px"; | |
//ifrm.style.width = ifrm.contentWindow.document.documentElement.getElementsByClassName('mw-body')[0].scrollWidth+50 +"px"; | |
} catch (e) { | |
return; | |
} | |
} | |
function addIframeIfNeeded () { | |
if(!inIframe()){ | |
if(document.getElementsByTagName("body")[0].parentElement.scrollHeight<document.documentElement.clientHeight*5+document.documentElement.scrollTop){ | |
var ifrm, src; | |
ifrm = document.createElement("iframe"); | |
if(window.location.href.includes("wiktionary.org")){ | |
src = "https://en.wiktionary.org/wiki/Special:RandomInCategory/English_lemmas#English"; | |
}else if (window.location.href.includes("wikiquote.org")){ | |
src = "https://en.wikiquote.org/wiki/Special:Random"; | |
} | |
ifrm.setAttribute("src", src); | |
ifrm.style.width = "100vw"; | |
ifrm.style.height = "5vh"; | |
ifrm.style.border = "0"; | |
ifrm.scrolling = "no"; | |
//document.getElementById("content").parentNode.insertBefore(ifrm, document.getElementById("mw-navigation")); | |
window.top.document.getElementsByClassName("mediawiki")[0].parentNode.appendChild(ifrm) | |
setTimeout(resizeIFrames,1500); | |
} | |
} | |
} | |
window.addEventListener('DOMContentLoaded', (event) => { | |
console.log('DOM fully loaded and parsed'); | |
}); | |
setTimeout(startup,2000); | |
setInterval(resizeIFrames,1000); | |
function startup () { | |
if(!inIframe()){ | |
addIframeIfNeeded(); | |
setInterval(addIframeIfNeeded,1000); | |
} | |
} | |
var styles = ` | |
#mw-head-base, #mw-page-base, #mw-head, #mw-panel, #mw-navigation, #footer, #siteNotice, .mw-footer-container, .vector-column-start, #p-lang-btn, .vector-header-container, .vector-page-toolbar{ | |
display: none; | |
} | |
.vector-toc-landmark { | |
display: none !important; | |
} | |
.mediawiki { | |
height: auto; | |
} | |
#content { | |
margin: 0; | |
} | |
@media screen { | |
body { | |
background-color: #8a8a8a; | |
} | |
} | |
body { | |
padding-bottom: 50px; | |
} | |
.mw-page-container { | |
padding: 0 !important; | |
} | |
` | |
var styleSheet = document.createElement("style") | |
styleSheet.innerText = styles | |
document.head.appendChild(styleSheet) | |
})(); |
also I only posted this because https://github.com/IsaacGemal/wikitok made the top of hackernews and it occurred to me that this userscript might be useful for other people :Y
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Running the userscript should make pages on Wiktionary and Wikiquote look like this when you scroll: