// ==UserScript== // @name EGS tweaks // @version 0.4.5 // @description EGS bells and whistles // @author /u/kuilin (kuilin@gmail.com) // @match *://*.egscomics.com/* // @match *://egscomics.com/* // @grant none // @updateURL https://raw.githubusercontent.com/likuilin/egs-greasemonkey-tweaks/master/script.js // ==/UserScript== (function() { 'use strict'; // inject entire userscript into page context // this is fine because the userscript requires no privileged things // nevertheless it is a workaround var code = (function() { 'use strict'; //feel free to edit these var settings = { //title replacement format (%asdf% = variable) titleReplace: true, titleReplaceString: "%oldTitle%
%superArcTitle%:
%arcTitle% #%comicId%", /* a la .bat, %variable% is variable. oldTitle = previously what was there in the line superArcTitle = bold super-arc in dropdown arcTitle = item in dropdown that this comic is under slug = the unique identifier (alphanumeric plus dashes) for this comic, part of canon URL title = the title of this specific comic (NB: comiccontrol takes the title Dan enters and normalizes it into the slug the title itself doesn't have to be alphanumeric for most old comics, it's just the date because the title /was/ the date but it doesn't have to be - for the question mark in the main series, the title is "Question Mark 01" etc and for recent ones, it's been Sister3-285 etc) comicId = the sequential # of the comic (NOT the old ID) as determined by the archive dropdown index, may change if comics are inserted so don't memorize numbers or something oldComicId = the old comic ID, or nothing if it postdates the cc update */ //numerical jumper //the numerical jumper adds a hash, like #id=123 to all comic pages, and watches that for changes, and initially //if it doesn't match the new sequence ID of the current comic, and that sequence ID exists, then the page will be redirected to the comic that does match //this allows a user to jump around comics numerically like how it was possible before the website update that removed ID numbers numericalJumper: true, //extra nav buttons showExtraNavButtons: true, showPrevArc: true, showCurArc: true, showRandom: true, showHelp: true, showReddit: true, showFacebook: true, showNextArc: true, moveDefaultNavButtonsAside: false, //"select a comic" selector modifications addDefault: true, //insert an entry for where we currently are prependComicId: true, //prepend the comicId (not the old comic ID) to the select a comic boldSuperArcs: true, //make the superarcs bold //top bar cosmetics autoScrollPastHeader: true, removeTopExtraSpace: true, //commentary section //hideCommentaryIfNoneExists: true, //hide the commentary section if there isn't any //this was actually implemented in the change, yay! showCommentaryDate: true, //show the previously-shown currently-hidden commentary date and time addInfoToCommentarySection: true, //add technical info about the current comic below the ad next to the commentary //keyboard navigation keyboardNavigation: true, keyboardNavigationKeys: { //JS keycodes, use -1 to disable left:37, down:-1, right:39, up:-1 //arrow keys, up and down disabled (not gonna override scrolling as a default lol) //left:37, down:40, right:39, up:38 //arrow keys, all enabled //left:65, down:83, right:68, up:87 //uncomment for wasd } }; var localStorageHeader = "EGStweaks_save_" var $ = window.jQuery; var retry; $(retry = function () { //canon-ize the link first //determine which comic it is (main, sketch, or np) using next or prev button var urlBase; if ($(".cc-prev").length > 0) { //previous button exists urlBase = $(".cc-prev").attr("href").split("/"); } else if ($(".cc-next").length > 0) { //next button exists (likely first comic) urlBase = $(".cc-next").attr("href").split("/"); } else return console.log("No next or previous button found"); //likely not a page with a comic, so we do nothing on those urlBase.pop(); urlBase = urlBase.join("/") + "/"; //title is provided in title of comic //notably, slug isn't var title = $("#cc-comic").attr("title"); if (!title) return console.log("No current title image found"); var urlCheck = urlBase.split("egscomics"); if (urlCheck.length != 2 || ( urlCheck[1] != ".com/comic/" && urlCheck[1] != ".com/sketchbook/" && urlCheck[1] != ".com/egsnp/")) return console.log("Base URL mismatch"); var section = urlBase.split("/")[3]; //see if we have cached archive dropdown information, to not ping two pages for every requested page because that would be rude //cache of the /archive page is invalidated and re-ajaxed upon any of: //* doesn't exist //* >24 hrs old //* latest exists and isn't in it var sectionComics; var latestSlug = $(".cc-last").attr("href"); //may be undefined if we're currently on the lastest one if (latestSlug) latestSlug = latestSlug.split("/").pop(); if (!( (sectionComics = localStorage.getItem(localStorageHeader + section)) && (sectionComics = JSON.parse(sectionComics)) && (typeof latestSlug == "undefined" ? sectionComics.by_slug[sectionComics.by_id[sectionComics.ids]].title == title : //if it is undefined, latest title must match sectionComics.by_slug.hasOwnProperty(latestSlug)) && //if it's not undefined, we have to have the latest slug (new Date() - sectionComics.updated < 24*60*60*1000))) { //invalidate and re-fetch sectionComics sectionComics = { by_slug: {}, by_id: {}, arcs: {}, super_arcs: {}, updated: +new Date(), ids: 0 }; console.log("Fetching archive dropdown"); //sometimes urlBase has the wrong protocol $.ajax(location.origin + urlBase.split("egscomics.com").pop() + "archive").done(function (src) { //cardinal sinTM - parsing html using regex var r = /