SniptaHF

Implements Snipta into HF

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         SniptaHF
// @namespace    https://hackforums.net/member.php?action=profile&uid=2525478
// @version      0.2
// @description  Implements Snipta into HF
// @author       TyrantKingBen
// @match        https://hackforums.net/*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_info
// ==/UserScript==

var width = GM_getValue(GM_info.script.name + "width", "360");
var height = GM_getValue(GM_info.script.name + "height", "560");

(function() {
    var menu = document.getElementsByClassName("menu");
    var calculatorButton = document.createElement("li");
    calculatorButton.innerHTML = "<a href='#' class='navButton'>Snipta</a>";

    calculatorButton.addEventListener("click", function(e) {
        if (e.ctrlKey) {
            width = prompt("Enter a new width (in px)") | "360";
            height = prompt("Enter a new height (in px)") | "560";
            GM_setValue(GM_info.script.name + "width", width);
            GM_setValue(GM_info.script.name + "height", height);

            e.preventDefault();
        }

        showCalculator();
    });

    menu[0].children[0].appendChild(calculatorButton);
})();

function showCalculator() {
    var sniptaContainer = document.createElement("div");
    sniptaContainer.style.width = "100%";
    sniptaContainer.style.height = "100%";
    sniptaContainer.style.position = "fixed";
    sniptaContainer.style.top = "0";
    sniptaContainer.style.left = "0";
    sniptaContainer.style.background = "black";
    sniptaContainer.style.opacity = "0";
    sniptaContainer.style.transition = "opacity 0.5s";

    var sniptaFrame = document.createElement("iframe");
    sniptaFrame.src = "https://snipta.com/";
    sniptaFrame.scrolling = "no";
    sniptaFrame.style.border = "none";
    sniptaFrame.style.width = width + "px";
    sniptaFrame.style.height = height + "px";
    sniptaFrame.style.position = "fixed";
    sniptaFrame.style.top = "50%";
    sniptaFrame.style.left = "50%";
    sniptaFrame.style.transform = "translate(-50%, -50%)";
    sniptaFrame.style.borderRadius = "10px";
    sniptaFrame.style.opacity = "0";
    sniptaFrame.style.transition = "opacity 0.5s";

    document.body.appendChild(sniptaContainer);
    document.body.appendChild(sniptaFrame);

    setTimeout(function() {
        sniptaContainer.style.opacity = "0.5";
        sniptaFrame.style.opacity = "1";
    }, 100);

    sniptaContainer.addEventListener("click", function() {
        sniptaContainer.style.opacity = "0";
        sniptaFrame.style.opacity = "0";

        setTimeout(function() {
            document.body.removeChild(document.body.lastChild);
            document.body.removeChild(document.body.lastChild);
        }, 500);
    });
}