hypnopics-collective image fixer

changes thumbnails href to full image for hover add ons - requires click-based get request because no pattern

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         hypnopics-collective image fixer
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  changes thumbnails href to full image for hover add ons - requires click-based get request because no pattern
// @author       You
// @match        https://hypnopics-collective.net/smf_forum/index.php?action=gallery*
// @grant        none
// ==/UserScript==

let scriptTag = document.createElement("script");
scriptTag.src = "https://code.jquery.com/jquery-2.2.4.js";
document.querySelector("head").appendChild(scriptTag);

newArr = Array.prototype.slice.call(document.getElementsByClassName("smalltext"), 0, document.getElementsByClassName("smalltext").length - 2);

newArr.forEach(el => el.innerHTML += el.innerText.slice(-5) === "Guest" ? "<br><span class='changeImg'>Change thumbnail href</span>" : "<span class='changeImg'>Change thumbnail href</span>");

Array.prototype.forEach.call(document.getElementsByClassName("changeImg"), function(el) {
    el.addEventListener("click", function(e) {
    el.innerText = "Changing...";
    $.ajax({
        type: "GET",
        url: el.parentNode.parentNode.children[window.location.href.match(/id=\d+/) || window.location.href.match(/u=\d+/) ? 1 : 0].href,
        success: function(data) {
            el.parentNode.parentNode.children[window.location.href.match(/id=\d+/) ||  window.location.href.match(/u=\d+/) ? 1 : 0].href = data.match(/https:\/\/hypnopics-collective\.net\/smf_forum\/gallery\/\d+\/\d+(-\d+)*\.\w+/)[0];
            el.innerText = "Changed!";
        },
        error: function(data) {
          console.log("error in ajax", error);
        }
    });
  });
});