follow page

10.4.2021, 17:52:31

Verzia zo dňa 05.06.2021. Pozri najnovšiu verziu.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, Greasemonkey alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey, % alebo Violentmonkey.

Na nainštalovanie skriptu si budete musieť nainštalovať rozšírenie, ako napríklad Tampermonkey alebo Userscripts.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie, ako napríklad Tampermonkey.

Na inštaláciu tohto skriptu je potrebné nainštalovať rozšírenie správcu používateľských skriptov.

(Už mám správcu používateľských skriptov, nechajte ma ho nainštalovať!)

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie, ako napríklad Stylus.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

Na inštaláciu tohto štýlu je potrebné nainštalovať rozšírenie správcu používateľských štýlov.

(Už mám správcu používateľských štýlov, nechajte ma ho nainštalovať!)

// ==UserScript==
// @name        follow page
// @namespace   Violentmonkey Scripts
// @match       https://rule34.xxx/index.php
// @grant       GM_setValue
// @grant       GM_getValue
// @version     1.0
// @author      usnkw
// @description 10.4.2021, 17:52:31
// @require     https://code.jquery.com/jquery-3.5.1.min.js
// ==/UserScript==

var followList = [];
var newList = [];
var a = null;

$("document").ready(async function() {
  if ( window.location == window.parent.location ) {	 
    var tags = /tags=(.*)/gm.exec(document.location.href) == null ? null : /tags=(.*)/gm.exec(document.location.href)[1];
    if(tags == null) return;
    if(GM_getValue('followList') == undefined){ GM_setValue('followList', []);}
    if(GM_getValue('newList') == undefined){ GM_setValue('newList', []);}
    a = document.createElement("a");
    followList = GM_getValue('followList');
    newList = GM_getValue('newList');
    tags = tags.split("+");
    for(var i = 0; i < tags.length; i++){
      if(followList.some( e => e['tagName'] == tags[i])){
          a.style.color = "red";
      }
      if(newList.some( e => e['tagName'] == tags[i])){
        newList = newList.filter( el => el.tagName != tags[i]);
        followList = followList.filter( el => el.tagName != tags[i]);
        followTag(); // remove the last saved post and refollow to refresh the post that is compared to 
        GM_setValue('newList', newList);
        console.log('newList', newList);
      }
    }
    a.innerHTML = "<3";
    a.style.cursor = "pointer";
    a.onclick = followTag;
    document.getElementsByClassName("awesomplete")[0].appendChild(a);

    var re = document.createElement("a");
    re.innerHTML = "look for news";
    re.style.cursor = "pointer";
    re.onclick = checkForNewPosts;
    document.getElementsByClassName("awesomplete")[0].appendChild(re);

    refreshSidebar();
    checkForNewPosts();
    setInterval(() => { checkForNewPosts(); refreshSidebar();}, 60000);
  }
});
async function refreshSidebar(){
  document.getElementsByClassName("sidebarRight")[0].innerHTML = "";
  followList.sort(function(a, b){
      var nameA=a.tagName.toLowerCase(), nameB=b.tagName.toLowerCase()
      if (nameA < nameB)
          return -1 
      if (nameA > nameB)
          return 1
      return 0
  })
  
  for(var i = 0; i < followList.length; i++){
    var tag = document.createElement("a");
    tag.innerHTML = followList[i].tagName + "<br>";
    tag.style.displayStyle = "inline";
    tag.style.padding = ".3em 1em .3em 1em";
    tag.style.lineHeight = "3";
    tag.style.cursor = "pointer";
    tag.style.backgroundColor = "#f55c51"
    tag.style.width = "100%";
    tag.style.borderRadius = "10px";
    tag.href = "https://rule34.xxx/index.php?page=post&s=list&tags=" + followList[i]["tagName"];
    if(newList.some( e => e['tagName'] == followList[i]["tagName"])){
       tag.style.backgroundColor = "#b6eb1a";
       tag.style.color = "#000000";
    }
    document.getElementsByClassName("sidebarRight")[0].appendChild(tag);
  }
}
async function checkForNewPosts(){
  for(var i = 0; i < followList.length; i++){
    a.innerHTML = "<3" + " checking: " + followList[i]["tagName"];
    var postId = await getFirstPostId("https://rule34.xxx/index.php?page=post&s=list&tags=" + followList[i]["tagName"]);
    console.log(followList[i]["tagName"] + "  : ", postId, followList[i]["postId"]);
    if(postId != followList[i]["postId"] && !(newList.some(e => e['tagName'] == followList[i]['tagName']))){
      newList.push({"tagName": followList[i]["tagName"], "postId":postId});
      GM_setValue('newList', newList);
      console.log('newList', newList);
    }
  }
  a.innerHTML = "<3";
  refreshSidebar();
}
async function followTag(){
  var tagname = document.getElementsByName("tags")[0].value;
  var festPostId = document.getElementsByClassName("thumb")[0].id;
  if(!followList.some( e => e['tagName'] == tagname)){
    followList.push({"tagName":tagname, "postId":festPostId});
    GM_setValue('followList', followList);
  }else{
    followList = followList.filter( el => el.tagName != tagname);
    GM_setValue('followList', followList);
  }
  a.style.color = a.style.color == "red" ? "#ffffff" : "red";
  refreshSidebar();
}
async function getFirstPostId(url){
  return new Promise(function(resolve, reject) {  
      var ifream = document.createElement("iframe");
      ifream.src = url;
      ifream.onload = function() {
          var elm = $("iframe").contents().find("span[class='thumb']")[0];
          resolve(elm.id);
          ifream.parentNode.removeChild(ifream);
      }
      document.body.appendChild(ifream); 
  });
}