From 1c4aae6dc5b5c578baa905580298bd308fe40e4c Mon Sep 17 00:00:00 2001 From: ECHibiki Date: Fri, 11 May 2018 00:12:33 -0400 Subject: [PATCH] Thread rebuilder fix --- builds/4-Free.user.js | 6 +-- src/docs.ts | 2 +- src/thread-rebuilder.ts | 128 ++++++++++++++++++++++++------------------------ 3 files changed, 68 insertions(+), 68 deletions(-) diff --git a/builds/4-Free.user.js b/builds/4-Free.user.js index 0a2b097..d25670d 100644 --- a/builds/4-Free.user.js +++ b/builds/4-Free.user.js @@ -12,7 +12,7 @@ var __extends = (this && this.__extends) || (function () { // @name 4Free-FSE [4chan X Enhancement] // @author ECHibiki - /qa/ // @description 4Free - Free Stuff Enhancments. 7 additional features on top of 4chanX -// @version 1.3.12 +// @version 1.3.13 // @namespace http://verniy.xyz/ // @match *://boards.4chan.org/* // @updateURL https://raw.githubusercontent.com/ECHibiki/4Free-FSE/master/builds/4-Free.user.js @@ -1082,8 +1082,8 @@ var ThreadRebuilder = /** @class */ (function (_super) { return _this; } ThreadRebuilder.prototype.init = function () { - var board_uproces = window.location.pathname; - this.board = board_uproces.substring(1, board_uproces.length - 1); + var pathname = window.location.pathname.substring(1); + this.board = pathname.substring(0, pathname.indexOf("/")); this.activate(); }; ThreadRebuilder.prototype.retrieveStates = function () { diff --git a/src/docs.ts b/src/docs.ts index 947d051..7b7f8e4 100644 --- a/src/docs.ts +++ b/src/docs.ts @@ -2,7 +2,7 @@ // @name 4Free-FSE [4chan X Enhancement] // @author ECHibiki - /qa/ // @description 4Free - Free Stuff Enhancments. 7 additional features on top of 4chanX -// @version 1.3.12 +// @version 1.3.13 // @namespace http://verniy.xyz/ // @match *://boards.4chan.org/* // @updateURL https://raw.githubusercontent.com/ECHibiki/4Free-FSE/master/builds/4-Free.user.js diff --git a/src/thread-rebuilder.ts b/src/thread-rebuilder.ts index 666823f..5061e25 100644 --- a/src/thread-rebuilder.ts +++ b/src/thread-rebuilder.ts @@ -20,8 +20,8 @@ class ThreadRebuilder extends FeatureInterface{ } init():void{ - var board_uproces = window.location.pathname; - this.board = board_uproces.substring(1, board_uproces.length - 1); + var pathname = window.location.pathname.substring(1); + this.board = pathname.substring(0, pathname.indexOf("/")); this.activate(); } @@ -156,72 +156,72 @@ class ThreadRebuilder extends FeatureInterface{ var URL = "https://www.archived.moe/_/api/chan/thread/?board=" + this.board + "&num=" + (document.getElementById("threadInput")).value; else var URL = "https://a.4cdn.org/" + this.board + "/thread/" + (document.getElementById("threadInput")).value + ".json"; - var xhr = new GM_xmlhttpRequest(({ - method: "GET", - url: URL, - responseType : "json", - onload: (data) => { - if(this.use_offsite_archive) - data = data.response["" + (document.getElementById("threadInput")).value]["posts"]; - else - data = data.response["posts"]; - if(data == undefined){ - alert("Invalid Thread ID: " + (document.getElementById("threadInput")).value + ". "); - } - else{ - link_arr.forEach((link_item)=>{ - for(var data_entry = 0 ; data_entry < data.length ; data_entry++){ - if(parseInt(link_item[0]) == parseInt(data[data_entry]["no"])){ - if(this.use_offsite_archive && data[data_entry]["comment_processed"] !== undefined) - responding_text.push([ [post_no, end_index], data[data_entry]["comment_processed"].replace(/(>>|https:\/\/www\.archived\.moe\/.*\/thread\/.*\/#)\d+/g, ""), link_item["media"]["safe_media_hash"] ]); - else if(data[data_entry]["com"] !== undefined) - responding_text.push([ [post_no, end_index], data[data_entry]["com"].replace(/(>>|#p)\d+/g, ""), data[data_entry]["md5"] ]); - else responding_text.push([ [post_no, end_index], undefined, data[data_entry]["md5"] ]); - break; - } + + var xhr = new GM_xmlhttpRequest(({ + method: "GET", + url: URL, + responseType : "json", + onload: (data) => { + if(this.use_offsite_archive) + data = data.response["" + (document.getElementById("threadInput")).value]["posts"]; + else + data = data.response["posts"]; + if(data == undefined){ + alert("Invalid Thread ID: " + (document.getElementById("threadInput")).value + ". "); + } + else{ + link_arr.forEach((link_item)=>{ + for(var data_entry = 0 ; data_entry < data.length ; data_entry++){ + if(parseInt(link_item[0]) == parseInt(data[data_entry]["no"])){ + if(this.use_offsite_archive && data[data_entry]["comment_processed"] !== undefined) + responding_text.push([ [post_no, end_index], data[data_entry]["comment_processed"].replace(/(>>|https:\/\/www\.archived\.moe\/.*\/thread\/.*\/#)\d+/g, ""), link_item["media"]["safe_media_hash"] ]); + else if(data[data_entry]["com"] !== undefined) + responding_text.push([ [post_no, end_index], data[data_entry]["com"].replace(/(>>|#p)\d+/g, ""), data[data_entry]["md5"] ]); + else responding_text.push([ [post_no, end_index], undefined, data[data_entry]["md5"] ]); + break; + } + } + }); + + var current_url = window.location.href; + var hash_index = current_url.lastIndexOf("#") != -1 ? current_url.lastIndexOf("#"): window.location.href.length; + var current_thread = window.location.href.substring(current_url.lastIndexOf("/")+1, hash_index); + var current_url = "https://a.4cdn.org/" + this.board + "/thread/" + current_thread + ".json"; + //open current thread to hunt down the text found in links + var xhr = new GM_xmlhttpRequest(({ + method: "GET", + url: current_url, + responseType : "json", + onload: (data)=>{ + data = data.response["posts"]; + if(data == undefined){ + alert("Invalid Thread ID: " + (document.getElementById("threadInput")).value + ". "); } - }); - - var current_url = window.location.href; - var hash_index = current_url.lastIndexOf("#") != -1 ? current_url.lastIndexOf("#"): window.location.href.length; - var current_thread = window.location.href.substring(current_url.lastIndexOf("/")+1, hash_index); - var current_url = "https://a.4cdn.org/" + this.board + "/thread/" + current_thread + ".json"; - //open current thread to hunt down the text found in links - var xhr = new GM_xmlhttpRequest(({ - method: "GET", - url: current_url, - responseType : "json", - onload: (data)=>{ - data = data.response["posts"]; - if(data == undefined){ - alert("Invalid Thread ID: " + (document.getElementById("threadInput")).value + ". "); - } - else{ - responding_text.forEach((response_item)=>{ - for(var data_entry = 0 ; data_entry < data.length ; data_entry++){ - if(data[data_entry]["com"] !== undefined && (response_item[1] == data[data_entry]["com"].replace(/(>>|#p)\d+/g, "") || response_item[1] == null) - && (response_item[2] == data[data_entry]["md5"] || response_item[2] == null)){ - var start_index = response_item[0][0].legth - response_item[0][1]; - text = text.substring(0, start_index) + ">>" + data[data_entry]["no"] + text.substring(response_item[0][1]); - break; - } - else if(response_item[2] !== undefined && response_item[2] == data[data_entry]["md5"]){ - var start_index = response_item[0][0].legth - response_item[0][1]; - text = text.substring(0, start_index) + ">>" + data[data_entry]["no"] + text.substring(response_item[0][1]); - break; - } + else{ + responding_text.forEach((response_item)=>{ + for(var data_entry = 0 ; data_entry < data.length ; data_entry++){ + if(data[data_entry]["com"] !== undefined && (response_item[1] == data[data_entry]["com"].replace(/(>>|#p)\d+/g, "") || response_item[1] == null) + && (response_item[2] == data[data_entry]["md5"] || response_item[2] == null)){ + var start_index = response_item[0][0].legth - response_item[0][1]; + text = text.substring(0, start_index) + ">>" + data[data_entry]["no"] + text.substring(response_item[0][1]); + break; } - }); - (document.getElementById("qr").getElementsByTagName("TEXTAREA")[0]).value = text; - document.getElementById("add-post").click(); - this.semaphore_posts++; - } + else if(response_item[2] !== undefined && response_item[2] == data[data_entry]["md5"]){ + var start_index = response_item[0][0].legth - response_item[0][1]; + text = text.substring(0, start_index) + ">>" + data[data_entry]["no"] + text.substring(response_item[0][1]); + break; + } + } + }); + (document.getElementById("qr").getElementsByTagName("TEXTAREA")[0]).value = text; + document.getElementById("add-post").click(); + this.semaphore_posts++; } - })); - } + } + })); } - })); - + } + })); }; -- 2.11.4.GIT