diff --git a/webcomic_reader.user.js b/webcomic_reader.user.js index 2c58845..35d6f68 100644 --- a/webcomic_reader.user.js +++ b/webcomic_reader.user.js @@ -43,7 +43,7 @@ var defaultSettings = { // ==UserScript== // @name Webcomic Reader - Sora Fix and Addition // @author Javier Lopez https://github.com/ameboide , fork by v4Lo https://github.com/v4Lo and by anka-213 http://github.com/anka-213 -// @version 2023.06.04.043900 +// @version 2023.08.03.223200 // @license MIT // @namespace http://userscripts.org/scripts/show/59842 // @description Can work on almost any webcomic/manga page, preloads 5 or more pages ahead (or behind), navigates via ajax for instant-page-change, lets you use the keyboard, remembers your progress, and it's relatively easy to add new sites @@ -725,10 +725,71 @@ var paginas = [ style: '#bb,#header{position:relative;}' }, { url: 'xkcd.', - img: ['//div[@id="comic"]//img'], + img: function(html, pos) { + console.log(html) + let img, origimg, hiRes; //Initlizing variables for ease of use + + //RegEx'ing up to find the high resolution image + let iReg = new RegExp(/(?<=
[\s\S]$[\s\S].*<\/div>)/im); + + //RegEx to find the original image + let imReg = new RegExp(/(?<=
[\s\S]$[\s\S].*<\/div>)/im); + + try { + //Try to find the high resolution link, and grab the href that leads to the high res image + hiRes = html.match(iReg)[0]; + + if (pos == 0 && confBool('xkcd2x') == true) { //Run only if this is on the initilizing page + + //Find the original image in the document + origimg = xpath('//div[@id="comic"]/img', document) + + //Find the original image in the variable "html" string + img = xpath('//div[@id="comic"]/img', html); + + //Set both document and html's src to the high resolution image + img.src = origimg.src = hiRes; + + } + + if (pos == 0 && confBool('xkcd2x') == false) { //If the HiRes toggle is off + img = xpath('//div[@id="comic"]/img', html); + } + + if (pos != 0 && confBool('xkcd2x') == true) { //Run on non-first loaded pages + + //Find and replace the html variables' instance of the image's src with the high resolution src + html = html.replace(imReg, hiRes); + + //xpath locator for the image in the html variable, now that it has the high resolution image as it's src + img = xpath('//div[@id="comic"]/img', html); + + } + + if (pos != 0 && confBool('xkcd2x') == false) { //If the HiRes toggle is off + img = xpath('//div[@id="comic"]/img', html); + } + + } catch(e) { //Error prevention on fresh loading of the page. + img = xpath('//div[@id="comic"]/img', html); + } + //Return the img as the capture rule. + return img; + }, first: '.="|<"', last: '.=">|"', - extra: ['
', ['//div[@id="ctitle"]'], function(html, pos) { + extra: ['
', + function(){ + //Name the button depending on the saved setting + if (confBool('xkcd2x') == true) { + HiResBtnText = "Switch to Normal Resolution"; + } else { + HiResBtnText = "Switch to Higher Resolution"; + } + //Returns custom High Res button to the Extras Div + return '
' + }, + '
', ['//div[@id="ctitle"]'], function(html, pos) { var href = xpath('//div[@id="comic"]//a/@href', html); return '
' + (href.indexOf('xkcd') >= 0 ? 'Large version' : 'Bonus Link!') + @@ -743,8 +804,18 @@ var paginas = [ var url = 'http://www.explainxkcd.com/wiki/index.php/' + nr; return 'Explain Xkcd'; }], - bgcol: '#fff' - }, + bgcol: '#fff', + js: function(dir, pos, html){ + + //Setup event for High Res button being pressed + setEvt('wcr_btnHiRes', 'click', toggleHighRes); + + //Copied/edited from the function that handles the Layout button + function toggleHighRes() { + toggleConfBool('xkcd2x'); //Check the saved setting + redirect(link[posActual]); //Reload the page to take new setting into effect + } + }, { url: 'dilbert.com', img: [['.img-comic']], back: '@title="Older Strip"',