Skip to content

Commit

Permalink
RuleFix -> Applied delay & timer in ScribbleHub and Webnovel to work …
Browse files Browse the repository at this point in the history
…on slow networks
  • Loading branch information
gmastergreatee committed Oct 8, 2022
1 parent 8e6fd08 commit c12df32
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions config/rules.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"rule_name": "ScribbleHub",
"url_regex": "(?:https://)(?:www\\.)*scribblehub\\.com/(?:read|series)/(\\d+)/*-*([a-z\\-]*)/*(?:[a-z]*)/*(\\d*).*",
"pagetype_code": "if (document.title.toLowerCase() == 'just a moment...') {\n return -2;\n}\n\ninjectJquery();\n\nvar match = (new RegExp(/(?:https:\\/\\/)(?:www\\.)*scribblehub\\.com\\/(?:read|series)\\/(\\d+)\\/*-*([a-z\\-]*)\\/*(?:[a-z]*)\\/*(\\d*).*/g)).exec(window.location.href);\nlet targUrl = 'https://www.scribblehub.com/series/' + match[1] + '/' + match[2] + '/';\nif (window.location.href != targUrl && !window.location.href.includes('/read/')) {\n return {\n retry: 1,\n nextURL: targUrl,\n };\n}\n\nreturn 0;",
"toc_code": "let retMe = {\n 'CoverURL': $('.fic_image img')[0].src,\n 'Title': $('.fic_title')[0].innerText,\n 'Summary': $('.wi_fic_desc')[0].innerText.replace(/\\n/g, '<br>'),\n 'ChapterCount': 0,\n 'ChapterURLs': [],\n};\n\nvar match = (new RegExp(/(?:https:\\/\\/)(?:www\\.)*scribblehub\\.com\\/(?:read|series)\\/(\\d+)\\/*-*([a-z\\-]*)\\/*(?:[a-z]*)\\/*(\\d*).*/g)).exec(window.location.href);\nvar postData = new Promise((resolve, reject) => {\n $.ajax({\n type: \"POST\",\n url: \"https://www.scribblehub.com/wp-admin/admin-ajax.php\",\n data: {\n action: \"wi_getreleases_pagination\",\n pagenum: -1,\n mypostid: parseInt(match[1]),\n },\n success: function(t) {\n let obj = document.createElement('div');\n obj.innerHTML = t;\n let anchors = $(obj).find('a');\n resolve(Array.from(anchors));\n },\n error: function() {\n reject(null);\n }\n });\n});\n\nlet chapterAnchors = await postData;\nretMe.ChapterURLs = chapterAnchors.map(x => x.href).reverse();\nretMe.ChapterCount = retMe.ChapterURLs.length;\n\nreturn retMe;",
"chapter_code": "let retMe = [\n {\n \"title\": $('.chapter-title')[0].innerText,\n \"content\": '<p>' + $('.chp_raw')[0].innerText.replace(/\\n+/g, '\\n').split('\\n').join('</p><p>') + '</p>',\n \"nextURL\": \"\" // when \"ChapterCount\" <= 0 & \"nextURL\" always comes non-empty\n // will loop infinitely unless something else(javascript) breaks\n },\n];\n\nreturn retMe;",
"toc_code": "let retMe = {\n 'CoverURL': $('.fic_image img')[0].src,\n 'Title': $('.fic_title')[0].innerText,\n 'Summary': $('.wi_fic_desc')[0].innerText.replace(/\\n/g, '<br>'),\n 'ChapterCount': 0,\n 'ChapterURLs': [],\n};\n\nawait sleep(100);\n\nvar match = (new RegExp(/(?:https:\\/\\/)(?:www\\.)*scribblehub\\.com\\/(?:read|series)\\/(\\d+)\\/*-*([a-z\\-]*)\\/*(?:[a-z]*)\\/*(\\d*).*/g)).exec(window.location.href);\nvar postData = new Promise((resolve, reject) => {\n $.ajax({\n type: \"POST\",\n url: \"https://www.scribblehub.com/wp-admin/admin-ajax.php\",\n data: {\n action: \"wi_getreleases_pagination\",\n pagenum: -1,\n mypostid: parseInt(match[1]),\n },\n success: function(t) {\n let obj = document.createElement('div');\n obj.innerHTML = t;\n let anchors = $(obj).find('a');\n resolve(Array.from(anchors));\n },\n error: function() {\n reject(null);\n }\n });\n});\n\nlet chapterAnchors = await postData;\nretMe.ChapterURLs = chapterAnchors.map(x => x.href).reverse();\nretMe.ChapterCount = retMe.ChapterURLs.length;\n\nreturn retMe;",
"chapter_code": "let retMe = [\n {\n \"title\": $('.chapter-title')[0].innerText,\n \"content\": '<p>' + htmlEncode($('.chp_raw')[0].innerText.replace(/\\n+/g, '\\n')).split('<br>').join('</p><p>') + '</p>',\n \"nextURL\": \"\" // when \"ChapterCount\" <= 0 & \"nextURL\" always comes non-empty\n // will loop infinitely unless something else(javascript) breaks\n },\n];\n\nreturn retMe;",
"url_blocks": ".js\n.css\ngoogleapis\ngoogletagmanager\n/siteimg/\n/avatar/\n/default/\n/themes/\n/seriesimg/\nwww.scribblehub.com/images/"
},
{
Expand Down Expand Up @@ -121,7 +121,7 @@
"rule_name": "WebNovel.com",
"url_regex": "(?:https://)*(?:www|m)\\.webnovel\\.com/([a-z]+)/([0-9a-z\\-A-Z~!\\(\\)%']+)_([0-9]+)",
"pagetype_code": "// chapter page 2 - actually checking JSON API\ntry {\n let jsonObj = JSON.parse(document.body.innerText);\n if (jsonObj.data.chapterInfo.chapterName)\n return 0;\n} catch { }\n\n// toc page\nlet toc = $('a[title=\"Table of Contents\"]');\nif (toc && toc.length == 1) {\n return 0;\n}\n\n// chapter page 1\nlet chapter = $('.cha-tit');\nif (chapter && chapter.length >= 1) {\n return 0;\n}",
"toc_code": "// throw error if TOCScript script run on chapter page\nlet chapter = $('.cha-tit');\nif (chapter && chapter.length == 1) {\n return null;\n}\n\nlet retMe = {\n 'CoverURL': $('.det-info img')[1].src,\n 'Title': $('.det-info h1')[0].innerText.trim(),\n 'Summary': $('.det-tab-pane p')[0].innerHTML.trim(),\n 'ChapterCount': parseInt($('.det-hd h2 strong span')[0].innerText),\n 'ChapterURLs': [],\n};\n\nlet waitSeconds = 0;\n$('a[title=\"Table of Contents\"]')[0].click();\n\nwhile ($('#contents .g_loading').length)\n{\n await sleep(1000);\n waitSeconds += 1;\n if (waitSeconds >= 10)\n return null;\n}\n\nretMe.ChapterURLs = Array.from($('#contents a')).slice(1).map(el => el.href);\n\nreturn retMe;",
"toc_code": "// throw error if TOCScript script run on chapter page\nlet chapter = $('.cha-tit');\nif (chapter && chapter.length == 1) {\n return null;\n}\n\nlet retMe = {\n 'CoverURL': $('.det-info img')[1].src,\n 'Title': $('.det-info h1')[0].innerText.trim(),\n 'Summary': $('.det-tab-pane p')[0].innerHTML.trim(),\n 'ChapterCount': parseInt($('.det-hd h2 strong span')[0].innerText),\n 'ChapterURLs': [],\n};\n\nlet waitSeconds = 0;\nawait sleep(100);\n$('a[title=\"Table of Contents\"]')[0].click();\n\nwhile ($('#contents .g_loading').length)\n{\n await sleep(1000);\n waitSeconds += 1;\n if (waitSeconds >= 20)\n return null;\n}\n\nretMe.ChapterURLs = Array.from($('#contents a')).slice(1).map(el => el.href);\n\nreturn retMe;",
"chapter_code": "let retMe = [\n {\n \"title\": \"\", // title of chapter\n \"content\": \"\", // content\n \"nextURL\": \"\" // when \"ChapterCount\" <= 0 & \"nextURL\" always comes non-empty\n // will loop infinitely unless something else(javascript) breaks\n },\n];\n\n// checking if REST API used\ntry {\n let jsonObj = JSON.parse(document.body.innerText);\n retMe[0].content = '<p>' + jsonObj.data.chapterInfo.contents.map(i => htmlEncode(i.content.replace('\\r\\n', ''))).join('</p><p>') + '</p>';\n retMe[0].title = jsonObj.data.chapterInfo.chapterName.replace(/^\\s*chapter\\s*\\d*\\s*:*\\s*\\.*\\s*-*\\s*/gi, '').trim();\n retMe[0].nextURL = window.location.href.split('&').map((el,i)=> i == 3 ? 'chapterId=' + jsonObj.data.chapterInfo.nextChapterId : el).join('&');\n return retMe;\n} catch { }\n\n// getting data from random chapter page\nif (chapInfo) {\n retMe[0].title = chapInfo.chapterInfo.chapterName.replace(/^\\s*chapter\\s*\\d*\\s*:*\\s*\\.*\\s*-*\\s*/gi, '').trim();\n retMe[0].content = \"<p>\" + chapInfo.chapterInfo.contents.map(i => htmlEncode(i.content.replace(/\\s*\\r+\\s*\\n+\\s*/g, ''))).join(\"</p><p>\") + \"</p>\";\n} else {\n retMe[0].title = $('#page .cha-tit h1').first().text().replace(/^\\s*chapter\\s*\\d*\\s*:*\\s*\\.*\\s*-*\\s*/gi, '').trim();\n retMe[0].content = \"<p>\" + Array.from($(\".cha-words p\")).map((i) => htmlEncode(i.innerHTML.trim())).join(\"</p><p>\") + \"</p>\";\n}\n\nlet nextChapData = $('link[rel=next]');\nif (nextChapData.length > 0) {\n let matches = new RegExp(/.*\\/(\\d+)\\/(\\d+)/).exec(nextChapData[0].href);\n let bookId = matches[1];\n let nextChapterId = matches[2];\n let _csrfToken = (await cookieStore.get('_csrfToken')).value;\n let _fsae_obj = (await cookieStore.get('_fsae'));\n if (_fsae_obj == null) {\n let curTime = dataLayer[0]['gtm.start'];\n if (curTime == null) {\n curTime = new Date().getTime();\n }\n await cookieStore.set('_fsae', curTime);\n _fsae_obj = { 'value': curTime };\n }\n retMe[0].nextURL = 'https://www.webnovel.com/go/pcm/chapter/getContent?' +\n '_csrfToken=' + _csrfToken +\n '&_fsae=' + _fsae_obj.value +\n '&bookId=' + bookId +\n '&chapterId=' + nextChapterId +\n '&encryptType=3&_=' + _fsae_obj.value;\n}\n\nreturn retMe;",
"url_blocks": "quora\ngoogle\n/emoji\n/recommend\n/bookReview\n/powerStone\n/checkStatus"
}
Expand Down

0 comments on commit c12df32

Please sign in to comment.