// ==UserScript==
// @name Eza's Homestuck Reader
// @namespace https://inkbunny.net/ezalias
// @description A mobile-friendly page simplifier for MSPaintAdventures.com
// @license MIT
// @license Public domain / No rights reserved
// @include http://www.mspaintadventures.com/*
// @version 1.0
// @grant none
// @downloadURL none
// ==/UserScript==
// MSPA on mobile is painful, so let's replace the page with an AJAX updater that only cares about the comic area.
// Scratch pages are like http://www.mspaintadventures.com/scratch.php?s=6&p=005954 which complicates using window.location.search.
// The transition is on page 005663. That page doesn't link it, the site itself redirects to scratch.php?s=6&p=005954. Same with any page in the scratch.php range.
// Ah, scratch.php pages don't have the same convenient 'begin comic content' comments.
// Hacky solution: find 'CREDITS', then open from next '
' after that index. End at ''?
// Backgrounds in Scratch and Trickster pages aren't quite right. E.g. Trickster pages should be all garish Z's. (Trickster mode: p=007614)
// Mobile link does not appear on Trickster pages. The whole nav bar is wacko.
// Act 7 super doesn't work. Ditto [s] Collide.
// Oh shit, password pages. That'll screw with preloading... but... oh well?
// Password pages work, but redirect you outside of #mobile. (c. p=008948, first password is HOME. No, not HOM3.)
// For usability, replace "what content" error message with a link somewhere. Frontpage? Homestuck's first page?
// Style isn't quite right on links. '==>' is supposed to be bold, and Scratch links are supposed to be green.
// Oh shit, Openbound. (c. p=007208)
// Link back to original from mobile? E.g. to fix Trickster & Scratch inconsistencies, and make broken game/video pages easy to navigate.
// Ah, maybe just link inside our fake HTML.
// Consider anchoring #mobile to the top of the page to automatically scroll up... er, except we aren't following real links. Hmm.
// Doesn't work around e.g. p=005935 because Flash elements load late. Fuck me. Maybe try again later.
// Doesn't work on Cascade, /cascade.php?s=6&p=6009 - total blank.
if( window.location.href.indexOf( '#mobile' ) > 0 ) { // On a #mobile page, blank everything and attempt to present a comic page.
// Replace the page with some simple divs and dummy text
document.body.innerHTML = "
";
// Setup the fake history for our fake links
window.onpopstate = function( event ) { update( event.state.update, 'content' ); }; // Faking the Back button: update() to a previous history state, which we also fake
history.replaceState( { update: window.location.href }, 'MS Paint Adventures', window.location.href ); // You are here. JS doesn't do this itself because fuck you.
// Call Update for whatever ?s=X&p=Y page we're on
update( window.location.search, 'content' );
} else { // If it's not #mobile then we're on unaugmented MSPA. Augment it with a link to the appropriate #mobile version.
// Mobile link from the front page has to be different because '/?s=...mobile' works, but '/&?s=...' doesn't. Dunno why it's a CORS error, though.
var mobile_link = window.location.href + "mobile"; // The '&' forces a reload despite being a misused anchor link
if( window.location.href.indexOf( '?s=' ) < 0 ) { mobile_link = "/?s=6#mobile"; } // Frontpage is Homestuck? Link Homestuck.
// "Mobile" link goes after the "Credits" link
var credits_index = document.body.innerHTML.indexOf( "CREDITS" ) + "CREDITS".length;
if( credits_index > 20 ) { // Sloppy not to check for indexOf > -1, but fuck, am I ever tired of verbose indexOf nonsense. Gimme some spliceAtText function.
document.body.innerHTML =
document.body.innerHTML.substring( 0, credits_index ) +
" | MOBILE" +
document.body.innerHTML.substring( credits_index );
}
}
// End of main execution.
// Grab a page, put the important stuff in one of our divs
function update( page_path, target_div ) {
var ajax = new XMLHttpRequest(); // Create AJAX object with which to fetch page
ajax.onreadystatechange = function () { // When the AJAX object updates -
if( ajax.readyState == 4 ) { // If the update state means "finished" -
// Grab comic content from the fetched HTML
var replacement_html = ajax.responseText.substring(
ajax.responseText.indexOf( '' ), // Alternately '' - but that misses Trickster fluff. Hmm.
ajax.responseText.indexOf( '' )
);
if( replacement_html == '' ) { // If the easy way failed (e.g. on Scratch pages), try again:
var replacement_html = ajax.responseText.substring(
ajax.responseText.indexOf( '
' )
);
}
// Consider inserting non-mobile link into #mobile pages here. Consolidate a function with main execution's "else" block if so: splice-text-at or something.
// Enable Flash content
while( replacement_html.indexOf( '