Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Automatic Preview Avn
- // @namespace https://avenoel.org/forum
- // @version 0.1
- // @description will take under the sea!
- // @author Me
- // @match https://avenoel.org/*
- // @grant GM_setValue
- // @grant GM_getValue
- // @require http://code.jquery.com/jquery-2.1.5.min.js
- // ==/UserScript==
- (function() {
- "use strict";
- let enabled = GM_getValue("sir-instprev-enabled", false);
- let btautoprev = $(document.createElement("button"));
- let btmanualprev = $("button.btn.preview-btn");
- btautoprev.addClass("btn btn-primary");
- btautoprev.attr("type", "button");
- btmanualprev.after(btautoprev);
- function buttons_update() {
- btautoprev.text("Prévis. Automatique : " + (enabled ? "Activé" : "Désactivé"));
- enabled ? btmanualprev.hide() : btmanualprev.show();
- enabled ? btautoprev.css("margin-left", "0px") : btautoprev.css("margin-left", "3px");
- GM_setValue("sir-instprev-enabled", enabled);
- }
- buttons_update();
- btautoprev.on("click", () => {enabled = !enabled; buttons_update()});
- $(".post-content").on("input paste change click", () => {
- if (!enabled)
- return;
- let text = $(".post-content").last().val();
- if (/^[\s]+$/.test(text) || text.length == 0) {
- $(".preview").html("");
- $(".preview").hide();
- } else {
- $.post("/previsualisation", {content: text}).done(
- (data) => { null !== data.error ? alert(data.error) :
- ($(".preview").html(data.content), $(".preview").show())
- });
- }
- });
- })();
Advertisement
Add Comment
Please, Sign In to add comment