Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @author SirSeingeur
- // @name Sir Select Cite
- // @namespace https://avenoel.org/forum
- // @version 0.1
- // @icon https://avenoel.org/favicon.ico
- // @match *://avenoel.org/*
- // @grant GM_addStyle
- // @grant GM_log
- // ==/UserScript==
- (function() {
- if (!$(".message-actions").length) {
- GM_log("there's no '.message-actions' on this page");
- } else if (!$("#form").length) {
- GM_log("there's no '#form' on this page");
- } else {
- GM_addStyle(`
- .ssc-open:hover {
- cursor: pointer;
- }
- `);
- let postContent = $(".post-content").last();
- $(".message-actions").each(function() {
- let pseudo = "undefined";
- let msgContent = $(this).closest(".message-wrapper").find(".message-content");
- let msgUrl = $(this).find(".message-quote").attr("href");
- // https://i.imgur.com/7j1k8I2.png
- // https://i.imgur.com/fMr3nE3.png
- let htmlIcon = $(`
- <li>
- <a class='message-quote ssc-open' title='Citer une partie du message'>
- <img src='https://i.imgur.com/7j1k8I2.png' alt='Icône citation partiel'/>
- </a>
- </li>
- `);
- let htmlSelect = $(`
- <div hidden>
- <textarea readonly class="form-control ssc-message" style='margin-bottom: 15px;' rows='8'></textarea>
- <div>
- <button type='button' class='btn btn-primary ssc-cancel'>Annuler</button>
- <button type='button' class='btn btn-primary ssc-cite'>Citer la sélection</button>
- </div>
- </div>
- `);
- let btOpen = htmlIcon.find(".ssc-open");
- let btCite = htmlSelect.find(".ssc-cite");
- let btCancel = htmlSelect.find(".ssc-cancel");
- let txMessage = htmlSelect.find(".ssc-message");
- let initialized = false;
- function hideSelect() {
- htmlSelect.hide();
- msgContent.show();
- }
- function showSelect() {
- msgContent.hide();
- htmlSelect.show();
- }
- btOpen.on("click", () => {
- if (htmlSelect.is(':visible')) {
- hideSelect();
- } else {
- if (initialized) {
- showSelect();
- return;
- }
- $.get(msgUrl).done(t => {
- if (null !== t.error)
- alert(t.error);
- else {
- initialized = true;
- pseudo = t.quote.split("\n")[0].slice(2);
- let message = t.quote.split("\n").slice(1).map(l => l.slice(2)).join("\n");
- txMessage.val(message);
- showSelect();
- }
- });
- }
- });
- btCancel.on("click", hideSelect);
- btCite.on("click", () => {
- let cite = txMessage.selection().split("\n").map(l => "> " + l).join("\n");
- postContent.val(`${postContent.val()}\n>>${pseudo}\n${cite}`);
- hideSelect();
- document.location = "#form";
- postContent.change();
- });
- $(this).append(htmlIcon);
- msgContent.after(htmlSelect);
- })
- }
- })();
- /*
- function(t) {
- t.preventDefault();
- $(this).parents(".topic-message").attr("id");
- $.get($(this).attr("href")).done(function(t) {
- null !== t.error ? alert(t.error) : ($(".post-content").last().val($(".post-content").last().val() + t.quote), $(".post-content").last().focus(), document.location = "#form")
- })
- }
- */
Advertisement
Add Comment
Please, Sign In to add comment