Guest User

Des scripts, c'est :noel:

a guest
Dec 10th, 2017
24
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @author        SirSeingeur
  3. // @name          Sir Select Cite
  4. // @namespace     https://avenoel.org/forum
  5. // @version       0.1
  6. // @icon          https://avenoel.org/favicon.ico
  7. // @match         *://avenoel.org/*
  8. // @grant         GM_addStyle
  9. // @grant         GM_log
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.  
  14.     if (!$(".message-actions").length) {
  15.         GM_log("there's no '.message-actions' on this page");
  16.     } else if (!$("#form").length) {
  17.         GM_log("there's no '#form' on this page");
  18.     } else {
  19.         GM_addStyle(`
  20.             .ssc-open:hover {
  21.                 cursor: pointer;
  22.             }
  23.         `);
  24.      
  25.         let postContent = $(".post-content").last();
  26.      
  27.         $(".message-actions").each(function() {
  28.             let pseudo = "undefined";
  29.             let msgContent = $(this).closest(".message-wrapper").find(".message-content");
  30.             let msgUrl = $(this).find(".message-quote").attr("href");
  31.          
  32.             // https://i.imgur.com/7j1k8I2.png
  33.             // https://i.imgur.com/fMr3nE3.png
  34.          
  35.             let htmlIcon = $(`
  36.                 <li>
  37.                     <a class='message-quote ssc-open' title='Citer une partie du message'>
  38.                         <img src='https://i.imgur.com/7j1k8I2.png' alt='Icône citation partiel'/>
  39.                     </a>
  40.                 </li>
  41.             `);
  42.            
  43.             let htmlSelect = $(`
  44.                 <div hidden>
  45.                     <textarea readonly class="form-control ssc-message" style='margin-bottom: 15px;' rows='8'></textarea>
  46.                     <div>
  47.                         <button type='button' class='btn btn-primary ssc-cancel'>Annuler</button>
  48.                         <button type='button' class='btn btn-primary ssc-cite'>Citer la sélection</button>
  49.                     </div>
  50.                 </div>
  51.             `);
  52.          
  53.             let btOpen = htmlIcon.find(".ssc-open");
  54.             let btCite = htmlSelect.find(".ssc-cite");
  55.             let btCancel = htmlSelect.find(".ssc-cancel");
  56.             let txMessage = htmlSelect.find(".ssc-message");
  57.             let initialized = false;
  58.          
  59.             function hideSelect() {
  60.                 htmlSelect.hide();
  61.                 msgContent.show();
  62.             }
  63.          
  64.             function showSelect() {
  65.                 msgContent.hide();
  66.                 htmlSelect.show();
  67.             }
  68.            
  69.             btOpen.on("click", () => {
  70.                 if (htmlSelect.is(':visible')) {
  71.                     hideSelect();
  72.                 } else {
  73.                     if (initialized) {
  74.                         showSelect();
  75.                         return;
  76.                     }
  77.  
  78.                     $.get(msgUrl).done(t => {
  79.                         if (null !== t.error)
  80.                             alert(t.error);
  81.                         else {
  82.                             initialized = true;
  83.                             pseudo = t.quote.split("\n")[0].slice(2);
  84.                             let message = t.quote.split("\n").slice(1).map(l => l.slice(2)).join("\n");
  85.                             txMessage.val(message);
  86.                             showSelect();
  87.                         }
  88.                     });
  89.                 }
  90.             });
  91.          
  92.             btCancel.on("click", hideSelect);
  93.             btCite.on("click", () => {
  94.                 let cite = txMessage.selection().split("\n").map(l => "> " + l).join("\n");
  95.                 postContent.val(`${postContent.val()}\n>>${pseudo}\n${cite}`);
  96.                 hideSelect();
  97.                 document.location = "#form";
  98.                 postContent.change();
  99.             });
  100.  
  101.             $(this).append(htmlIcon);
  102.             msgContent.after(htmlSelect);
  103.         })
  104.     }
  105.  
  106. })();
  107.  
  108. /*
  109. function(t) {
  110.   t.preventDefault();
  111.   $(this).parents(".topic-message").attr("id");
  112.   $.get($(this).attr("href")).done(function(t) {
  113.     null !== t.error ? alert(t.error) : ($(".post-content").last().val($(".post-content").last().val() + t.quote), $(".post-content").last().focus(), document.location = "#form")
  114.   })
  115. }
  116. */
Advertisement
Add Comment
Please, Sign In to add comment