Last active
September 3, 2017 10:56
-
-
Save Dither/7c4b62daef0b1f5c2938a1f59c753613 to your computer and use it in GitHub Desktop.
EgScans reader service script for AutoPatchWork mod
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== | |
// @description read.egscans.com reader service script for AutoPatchWork mod. | |
// @include http://read.egscans.com/* | |
// ==/UserScript== | |
(function(){ | |
var on, off, trigger; | |
var base_url = 'http://read.egscans.com/', | |
current_index = 0, | |
current_chapter = null, | |
is_new_chapterter = false, | |
next_chapter = null, | |
img_array = [], | |
null_chapter = '', | |
img_array_len = 0; | |
function currentChapterLink(index) { | |
return current_chapter + '/' + current_index; | |
} | |
function updateChapterVariables(nodes, url, initial) { | |
var scripts = nodes.querySelectorAll('script'); | |
for (var text = '', i = 0; i < scripts.length; i++) { | |
if (scripts[i].text.indexOf('var img_html') !== -1) { | |
text = scripts[i].text; | |
is_new_chapterter = false; | |
current_chapter = url; | |
current_index = 0; | |
next_chapter = base_url + text.match(/next_chap\s*=\s*["']([^;"]*)["']/)[1]; | |
img_array = text.match(/img_url.push\('([^']+)/g); | |
img_array_len = img_array.length - 1; | |
for (var j = 0; j < img_array.length; j++) img_array[j] = base_url + img_array[j].replace('img_url.push(\'',''); | |
break; | |
} | |
} | |
} | |
function generateBody(index, url) { | |
return '<div id="image_frame"><a href="' + url + '" class="unselectable"><img src="' + img_array[index] + '" class="picture" /></a></div>'; | |
} | |
function generateTitle(index, title) { | |
return current_chapter.replace(base_url, '').replace(/[_\/]/g,' ').replace(/\s*Chapter\s*/i,': ch.').replace(/\s*\(\s*Volume\s*\d+\s*\)\s*/i,'') + ' p.' + index;; | |
} | |
function terminateAPW() { | |
off('request'); | |
off('load'); | |
event.preventDefault(); | |
event.stopPropagation(); | |
trigger('terminated', { message: 'Last chapter reached'}); | |
} | |
function isChapter(chapter) { | |
return chapter && chapter !== null_chapter && chapter.indexOf('javascript:') < 0; | |
} | |
function handleNewPageLink(event) { | |
is_new_chapterter = false; | |
if (current_index < img_array_len) { | |
event.detail.norequest = true; | |
current_index += 1; | |
} else { | |
is_new_chapterter = true; | |
if (isChapter(next_chapter)) event.detail.link = next_chapter; | |
else event.detail.link.href = ''; | |
} | |
} | |
function handleNewPageLoad(event) { | |
if (is_new_chapterter) { | |
updateChapterVariables(event.detail.htmlDoc, event.detail.url, false); | |
if (!isChapter(next_chapter)) terminateAPW(); | |
} else { | |
event.detail.url = currentChapterLink(current_index); | |
} | |
event.detail.htmlDoc.body.innerHTML = generateBody(current_index, event.detail.url); | |
var tl = document.querySelector('title'); | |
tl.textContent = generateTitle(current_index, ''); | |
} | |
document.addEventListener('AutoPatchWork.ready', function() { | |
trigger = window.AutoPatchWorked.trigger; | |
on = window.AutoPatchWorked.on; | |
off = window.AutoPatchWorked.off; | |
on('request', handleNewPageLink); | |
on('load', handleNewPageLoad); | |
updateChapterVariables(document, '', true); | |
current_chapter = location.href.replace(/\/\d+$/,''); | |
if (!~current_chapter.indexOf('Chapter_')) { current_chapter = current_chapter.replace(/\/$/,''); current_chapter += '/Chapter_001'; } | |
current_index = parseInt(location.pathname.match(/(\d+)$/)[1], 10) - 1; | |
trigger('siteinfo', { | |
siteinfo : { | |
url: '^http://read\.egscans\.com/', | |
pageElement: 'id(\"image_frame\")', | |
nextLink: '//a', | |
forceIframe: false, | |
cssPatch: '.picture { max-width: 1200px!important; height: auto!important;min-height: 290px!important;} #omv table .mid { padding: 10px 0px!important; } .autopagerize_link { color: #009 !important;} .autopagerize_link:hover { color: #777 !important;} .autopagerize_page_separator_blocks+* img { min-width: 100px !important;} #image_frame {min-height: 700px;}' | |
} | |
}); | |
}, false); | |
}()); |
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
{ | |
"SERVICE":"true", | |
"url":"^https?://read\\.egscans\\.com/", | |
"jsPatch":"(function(){\nvar on, off, trigger;\nvar base_url = 'http://read.egscans.com/',\ncurrent_index = 0,\ncurrent_chapter = null,\nis_new_chapterter = false,\nnext_chapter = null,\nimg_array = [],\nnull_chapter = '',\nimg_array_len = 0;\n\nfunction currentChapterLink(index) {\nreturn current_chapter + '/' + current_index;\n}\n\nfunction updateChapterVariables(nodes, url, initial) {\nvar scripts = nodes.querySelectorAll('script');\nfor (var text = '', i = 0; i < scripts.length; i++) {\nif (scripts[i].text.indexOf('var img_html') !== -1) {\ntext = scripts[i].text;\nis_new_chapterter = false;\ncurrent_chapter = url;\ncurrent_index = 0;\nnext_chapter = base_url + text.match(/next_chap\\s*=\\s*[\"']([^;\"]*)[\"']/)[1];\nimg_array = text.match(/img_url.push\\('([^']+)/g);\nimg_array_len = img_array.length - 1;\nfor (var j = 0; j < img_array.length; j++) img_array[j] = base_url + img_array[j].replace('img_url.push(\\'','');\nbreak;\n}\n}\n}\n\nfunction generateBody(index, url) {\nreturn '<div id=\"image_frame\"><a href=\"' + url + '\" class=\"unselectable\"><img src=\"' + img_array[index] + '\" class=\"picture\" /></a></div>';\n}\n\nfunction generateTitle(index, title) {\nreturn current_chapter.replace(base_url, '').replace(/[_\\/]/g,' ').replace(/\\s*Chapter\\s*/i,': ch.').replace(/\\s*\\(\\s*Volume\\s*\\d+\\s*\\)\\s*/i,'') + ' p.' + index;;\n}\n\nfunction terminateAPW() {\noff('request');\noff('load');\nevent.preventDefault();\nevent.stopPropagation();\ntrigger('terminated', { message: 'Last chapter reached'});\n}\n\nfunction isChapter(chapter) {\nreturn chapter && chapter !== null_chapter && chapter.indexOf('javascript:') < 0;\n}\n\nfunction handleNewPageLink(event) {\nis_new_chapterter = false;\nif (current_index < img_array_len) {\nevent.detail.norequest = true;\ncurrent_index += 1;\n} else {\nis_new_chapterter = true;\nif (isChapter(next_chapter)) event.detail.link = next_chapter;\nelse event.detail.link.href = '';\n}\n}\n\nfunction handleNewPageLoad(event) {\nif (is_new_chapterter) {\nupdateChapterVariables(event.detail.htmlDoc, event.detail.url, false);\nif (!isChapter(next_chapter)) terminateAPW();\n} else {\nevent.detail.url = currentChapterLink(current_index);\n}\n\nevent.detail.htmlDoc.body.innerHTML = generateBody(current_index, event.detail.url);\nvar tl = document.querySelector('title');\ntl.textContent = generateTitle(current_index, '');\n}\n\ndocument.addEventListener('AutoPatchWork.ready', function() {\ntrigger = window.AutoPatchWorked.trigger;\non = window.AutoPatchWorked.on;\noff = window.AutoPatchWorked.off;\non('request', handleNewPageLink);\non('load', handleNewPageLoad);\nupdateChapterVariables(document, '', true);\n\ncurrent_chapter = location.href.replace(/\\/\\d+$/,'');\nif (!~current_chapter.indexOf('Chapter_')) { current_chapter = current_chapter.replace(/\\/$/,''); current_chapter += '/Chapter_001'; }\ncurrent_index = parseInt(location.pathname.match(/(\\d+)$/)[1], 10) - 1;\n\ntrigger('siteinfo', {\nsiteinfo : {\nurl: '^http://read\\.egscans\\.com/',\npageElement: 'id(\"image_frame\")',\nnextLink: '//a',\nforceIframe: false,\ncssPatch: '.picture { max-width: 1200px!important; height: auto!important;min-height: 290px!important;} #omv table .mid { padding: 10px 0px!important; } .autopagerize_link { color: #009 !important;} .autopagerize_link:hover { color: #777 !important;} .autopagerize_page_separator_blocks+* img { min-width: 100px !important;} #image_frame {min-height: 700px;}'\n}\n});\n}, false);\n}());" | |
}, |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment