Greasy Fork is available in English.

Kaskus Invalid Page Skipper

Deal with Kaskus's invalid page

< Valutazione su Kaskus Invalid Page Skipper

Recensione: Bene - lo script funziona

zoz
§
Pubblicato: 19/02/2016

-

var host = document.location.host;

function goToLastPost(url) {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var parser = new DOMParser();
var doc = parser.parseFromString(xhttp.responseText, "text/html");
var norPosts = doc.getElementsByClassName('nor-post');

if (norPosts.length > 0) {
var lastNorPostId = norPosts[norPosts.length-1].id;
var lastPostId = lastNorPostId.substring(4);
var newUrl = "http://" + host + "/post/" + lastPostId + "#" + lastNorPostId;

window.location.href = newUrl;
}
}};

xhttp.open("GET", url, true);
xhttp.send();
}

var listMessages = document.getElementsByClassName('list-message');
if (listMessages.length > 0) {
if (listMessages[0].innerHTML.indexOf('Invalid Thread specified') != -1) {
var pathNames = document.location.pathname.split('/');
var threadId = pathNames[2];

if (pathNames[1] == 'thread') {
var newUrl = "http://" + host + "/thread/" + threadId + "/-/" + (pathNames[4] - 1);
window.location.href = newUrl;
}
else if (pathNames[1] == 'lastpost') {
var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
var respText = xhttp.responseText;

var parser = new DOMParser();
var doc = parser.parseFromString(xhttp.responseText, "text/html");
var pageCountEls = doc.getElementsByClassName('page-count');

if (pageCountEls.length > 0) {
var pageCountElTexts = pageCountEls[0].innerHTML.split(" ");
var lastPageNum = pageCountElTexts[pageCountElTexts.length-1];
var newUrl = "http://" + host + "/thread/" + threadId + "/-/" + (lastPageNum - 1);

goToLastPost(newUrl);
}
}};

xhttp.open("GET", "http://" + host + "/thread/" + threadId, true);
xhttp.send();
}
}
}

Pubblica risposta

Accedi per pubblicare una risposta.