follow page

10.4.2021, 17:52:31

Verze ze dne 12. 06. 2021. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name        follow page
// @namespace   Violentmonkey Scripts
// @match       *://rule34.xxx/*
// @grant       GM_setValue
// @grant       GM_getValue
// @version     1.3
// @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;
var auto = false;

$("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'].trim() == tags[i].trim())){
          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();
  
    if(auto){
      checkForNewPosts();
      setInterval(() => { checkForNewPosts(); refreshSidebar();}, 600000);
    }
  }
});
async function refreshSidebar(){
  var sideElm = document.getElementsByClassName("sidebarRight")[0] == undefined? document.getElementsByClassName("content")[0] : document.getElementsByClassName("sidebarRight")[0];
  sideElm.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";
    }
    sideElm.appendChild(tag);
  }
}
async function checkForNewPosts(){
  for(var i = 0; i < followList.length; i++){
    a.innerHTML = "<3" + " checking: " + followList[i]["tagName"] + "<br>";
    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] == undefined ? 0 : document.getElementsByClassName("thumb")[0].id;
  
  if(!followList.some( e => e['tagName'].trim() == tagname.trim())){
    followList.push({"tagName":tagname, "postId":festPostId});
    GM_setValue('followList', followList);
  }else{
    followList = followList.filter( el => el.tagName.trim() != tagname.trim());
    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 ==  undefined ? 0 : elm.id);
          ifream.parentNode.removeChild(ifream);
      }
      document.body.appendChild(ifream); 
  });
}