Advertisement
Guest User

Untitled

a guest
Mar 26th, 2018
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         RuMinePP
  3. // @namespace    https://ru-minecraft.ru/
  4. // @version      1.3.0
  5. // @description  suka
  6. // @author       (You)
  7. // @match        https://ru-minecraft.ru/*
  8. // @grant        none
  9. // ==/UserScript==
  10.  
  11. window.RMPPVersion = "v1.3.0-beta";
  12.  
  13. (function() {
  14.     const code = main.toString().slice(17, -1);
  15.     let script = document.createElement("script");
  16.  
  17.     script.appendChild(document.createTextNode(code));
  18.  
  19.     document.body.appendChild(script);
  20.  
  21.     Modules.load();
  22. })();
  23.  
  24. function main() {
  25.     let DB = {
  26.         _queue: [],
  27.         init: function(cb) {
  28.             DB._open = indexedDB.open("RuMinePP_DB", 1);
  29.            
  30.             DB._open.onsuccess = function() {
  31.                 DB.db = DB._open.result;
  32.             }
  33.  
  34.             DB._open.onupgradeneeded = function() {
  35.                 DB.db = DB._open.result;
  36.  
  37.                 let store = DB.db.createObjectStore("MessageHistory", { keyPath: "id", autoIncrement: true });
  38.                 store.createIndex("messageId", "messageId", { unique: false });
  39.                 store.createIndex("content", "content", { unique: false });
  40.             }
  41.         },
  42.         processQueue: function() {
  43.             let tx = DB.db.transaction("MessageHistory", "readwrite");
  44.             let store = tx.objectStore("MessageHistory");
  45.  
  46.             let el = null;
  47.  
  48.             while (el = DB._queue.shift()) {
  49.                 store.put({
  50.                     messageId: el[0],
  51.                     content: el[1]
  52.                 });
  53.             }
  54.         },
  55.         getMessageHistory: function(id, cb) {
  56.             let result = [];
  57.  
  58.             DB.db
  59.                 .transaction("MessageHistory", "readonly")
  60.                 .objectStore("MessageHistory")
  61.                 .openCursor().onsuccess = function(event) {
  62.                     let cursor = event.target.result;
  63.  
  64.                     if (cursor) {
  65.                         if (cursor.value.messageId === id)
  66.                             result.push(cursor.value.content);
  67.  
  68.                         cursor.continue();
  69.                     } else {
  70.                         cb(result);
  71.                     }
  72.                 }
  73.         },
  74.         pushQueue(id, content) {
  75.             DB._queue.push([id, content]);
  76.         }
  77.     };
  78.     let HTML = {
  79.         _pages: {},
  80.         register: function(name, content) {
  81.             HTML._pages[name] = encodeURIComponent(content);
  82.         },
  83.         get: function(name) {
  84.             return decodeURIComponent(HTML._pages[name]);
  85.         }
  86.     };
  87.     const Injector = {
  88.         before: function(fn, inj) {
  89.             let self = this;
  90.  
  91.             return function() {
  92.                 inj.apply(self, arguments);
  93.                 return fn.apply(self, arguments);
  94.             }
  95.         },
  96.         after: function(fn, inj) {
  97.             let self = this;
  98.  
  99.             return function() {
  100.                 const res = fn.apply(self, arguments);
  101.                 inj.apply(self, arguments);
  102.                 return res;
  103.             }
  104.         }
  105.     };
  106.     const Modules = {
  107.         _modules: [],
  108.         registerModule: function(name, fn) {
  109.             Modules._modules.push({ name: name, fn: fn });
  110.         },
  111.         load: function() {
  112.             if (window.location.href === "https://ru-minecraft.ru/index.php?action=logout") return;
  113.  
  114.             if (localStorage.getItem("_logout") === "do") {
  115.                 document.write("Вхожу в аккаунт...");
  116.                 localStorage.setItem("_logout", "refresh");
  117.                 return setTimeout(() => window.location.href = "https://ru-minecraft.ru/", 1000);
  118.             }
  119.  
  120.             if (localStorage.getItem("_logout") === "refresh") {
  121.                 localStorage.setItem("_logout", "1");
  122.                 Modules._modules.find(e => e.name === "MultiAccount").fn();
  123.                 return window.loginMultiaccount();
  124.             }
  125.  
  126.             if (!$(".loginset")[1]) return;
  127.             if (window.location.href.startsWith("https://ru-minecraft.ru/out?")) return;
  128.  
  129.             try {
  130.                 Notification.requestPermission();
  131.  
  132.                 Modules._modules.forEach(function(m) {
  133.                     console.log(m.name + " enabled? " + (localStorage.getItem(m.name + "_enabled") !== "0"));
  134.                     if (localStorage.getItem(m.name + "_enabled") !== "0") m.fn();
  135.                 });
  136.             } catch (e) {
  137.                 document.write("<pre><center><h1>Невозможно инициализировать RuMine++</h1></center><br><br>");
  138.                 document.write(e.stack + "");
  139.                 document.write("<br><br><i>" + navigator.userAgent + "</i></pre>");
  140.             }
  141.         }
  142.     };
  143.     const PageAPI = {
  144.         getForumMessages: function(content) {
  145.             return Array.from($("li.msg", content ? $(content) : undefined)).slice(0, -1);
  146.         },
  147.         getForumPage: function(content) {
  148.             try {
  149.                 return ~~$(".txt_info_pages", content ? $(content) : undefined)[1].innerHTML.split(" ").pop();
  150.             } catch(e) {
  151.                 return 1;
  152.             }
  153.         },
  154.         appendForumMessage: function(el) {
  155.             $(".contentBoxTopicMessageList")[0].insertBefore(el, document.getElementById("addNewMsg"));
  156.         },
  157.         appendHistoryBtn: function(msg) {
  158.             let el = document.createElement("a");
  159.  
  160.             el.href = "#";
  161.             el.onclick = function() {
  162.                 editHistory(PageAPI.getMessageId(msg));
  163.                 return false;
  164.             }
  165.             el.innerHTML = "История редактирования";
  166.  
  167.             let msgEl = $(".msgIControl", $(msg))[0];
  168.  
  169.             if (!msgEl) return;
  170.  
  171.             msgEl.appendChild(el);
  172.         },
  173.         isForumTopic: function() {
  174.             return window.location.href.startsWith("https://ru-minecraft.ru/forum/showtopic-");
  175.         },
  176.         getMessageInfo: function(msg) {
  177.             const username = $(".autorInfo > p > a", $(msg))[0].innerHTML;
  178.             const avatar = $(".avatar > a > img", $(msg))[0].src;
  179.             const text = $("div[id^='MsgTextBox-']", $(msg))[0].innerText;
  180.  
  181.             return {
  182.                 username: username,
  183.                 avatar: avatar,
  184.                 text: text
  185.             }
  186.         },
  187.         getMessageId: function(msg) {
  188.             let topic = window.location.href.slice("https://ru-minecraft.ru/forum/showtopic-".length);
  189.             topic = topic.slice(0, topic.indexOf("/"));
  190.             const msgId = $(".getMessageLinck", $(msg)).text().slice(1);
  191.             return topic + "_" + msgId;
  192.         },
  193.         getMessageHTML: function(msg) {
  194.             let html = $("div[id^='MsgTextBox-']", $(msg)).html().trim();
  195.             return html.slice(0, html.indexOf('<div class="likeBox-'));
  196.         },
  197.         insertCustomEmoticon: function(url) {
  198.             doInsert("[img]" + url + "[/img]\n\n", "", false);
  199.             $("#bullet_energy_emos").dialog("close");
  200.             window.ie_range_cache = null;
  201.         },
  202.         getOnline: function(content) {
  203.             return Array.from(
  204.                 $("span",
  205.                     $(
  206.                         $(".userClin", content ? $(content) : undefined)[0]
  207.                     )
  208.                 ).not("[style='color:#9CA1A5']")
  209.             ).map(e => e.innerText);
  210.         },
  211.         getUserInfo: function(username, cb) {
  212.             // TODO: implement other
  213.  
  214.             $.ajax({
  215.                 url: "https://ru-minecraft.ru/engine/ajax/profile.php?name=" + username + "&skin=ru-minecraft",
  216.                 success: function(content) {
  217.                     const e = $(content);
  218.  
  219.                     const avatar = $("img", e)[0].src;
  220.  
  221.                     cb({
  222.                         avatar: avatar
  223.                     });
  224.                 }
  225.             });
  226.         },
  227.         login: function(login, password, cb) {
  228.             $.ajax({
  229.                 method: "POST",
  230.                 url: "https://ru-minecraft.ru/",
  231.                 data: {
  232.                     login_name: login,
  233.                     login_password: password,
  234.                     login: "submit"
  235.                 },
  236.                 success: function(body, status, xhr) {
  237.                     cb(true);
  238.                 },
  239.                 error: function() {
  240.                     cb(false);
  241.                 }
  242.             });
  243.         },
  244.         popup: function (title, body, buttons) {
  245.             $("#dlepopup").remove();
  246.             $("body").append("<div id='dlepopup' title='" + title + "' style='display:none'>" + body + "</div>");
  247.             $('#dlepopup').dialog({
  248.                 autoOpen: true,
  249.                 width: 550,
  250.                 dialogClass: "modalfixed",
  251.                 buttons: buttons
  252.             });
  253.         },
  254.         openWithPost: function(url, data) {
  255.             $("#Form").remove();
  256.  
  257.             let form = document.createElement("form");
  258.             let target = "w" + Math.random();
  259.  
  260.             form.setAttribute("id", "Form");
  261.             form.setAttribute("method", "POST");
  262.             form.setAttribute("action", url);
  263.             form.setAttribute("target", target);
  264.  
  265.             Object.keys(data).forEach(function(key) {
  266.                 let input = document.createElement("input");
  267.  
  268.                 input.setAttribute("type", "hidden");
  269.                 input.setAttribute("name", key);
  270.                 input.setAttribute("value", data[key]);
  271.  
  272.                 form.appendChild(input);
  273.             });
  274.  
  275.             document.body.appendChild(form);
  276.  
  277.             window.open("", target, 'height=900,width=1250,resizable=0,scrollbars=1');
  278.             form.submit();
  279.         }
  280.     };
  281.     Modules.registerModule("CustomEmoticons", function() {
  282.         if (!PageAPI.isForumTopic()) return;
  283.  
  284.         if (!localStorage.getItem("emoticons_urls")) localStorage.setItem("emoticons_urls", "");
  285.  
  286.         const emoticons = localStorage.getItem("emoticons_urls").split("\n");
  287.  
  288.         window.ins_emo = Injector.after(window.ins_emo, function() {
  289.             let container = $("#bullet_energy_emos > div > table > tbody")[0];
  290.      
  291.             let text = document.createElement("tr");
  292.             text.innerHTML = "= Кастомные =";
  293.             let textend = document.createElement("tr");
  294.             textend.innerHTML = "= Основные =";
  295.          
  296.             container.insertBefore(text, container.firstChild);
  297.             container.insertBefore(textend, container.children[1]);
  298.          
  299.             let current = null;
  300.          
  301.             emoticons.forEach(function(e, i) {
  302.                 if (i % 4 === 0) {
  303.                     current = document.createElement("tr");
  304.                     container.insertBefore(current, textend);
  305.                 }
  306.          
  307.                 let el_a = document.createElement("a");
  308.                 let el = document.createElement("img");
  309.                 let el_td = document.createElement("td");
  310.          
  311.                 el.setAttribute("class", "emoji");
  312.                 el.setAttribute("src", e);
  313.                 el.setAttribute("width", "64px");
  314.                 el_a.setAttribute("onclick", "PageAPI.insertCustomEmoticon('" + e + "'); return false;");
  315.                 el_a.setAttribute("href", "#");
  316.                 el_td.setAttribute("style", "padding:5px;");
  317.                 el_td.setAttribute("align", "center");
  318.          
  319.                 el_a.appendChild(el);
  320.                 el_td.appendChild(el_a);
  321.                 current.appendChild(el_td);
  322.             });
  323.         });
  324.     });
  325.     Modules.registerModule("EditPreview", function() {
  326.         window.ajax_prep_for_edit = Injector.after(window.ajax_prep_for_edit, function(id, mode) {
  327.             if (mode !== "short") return;
  328.  
  329.             let button = document.createElement("button");
  330.             let span = document.createElement("span");
  331.  
  332.             button.setAttribute("type", "button");
  333.             button.setAttribute("class", "ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only");
  334.             button.setAttribute("role", "button");
  335.             button.setAttribute("aria-disabled", "false");
  336.  
  337.             span.setAttribute("class", "ui-button-text");
  338.             span.innerHTML = "Превью";
  339.  
  340.             button.appendChild(span);
  341.  
  342.             button.onclick = function() {
  343.                 const title = $("input[id^='edit-title-']")[0].value;
  344.                 const shortStory = $("textarea[id^='dleeditnews']")[0].value;
  345.                 const fullStory = $("textarea[id^='dleeditfullnews']")[0].value;
  346.  
  347.                 PageAPI.openWithPost("/engine/preview.php",
  348.                     {
  349.                         "catlist[]":"",
  350.                         "title": title,
  351.                         "xfield[name]": "",
  352.                         "short_story": shortStory,
  353.                         "full_story": fullStory,
  354.                         "mod": "preview",
  355.                         "approve": "1"
  356.                     }
  357.                 );
  358.             }
  359.  
  360.             function tryAdd() {
  361.                 if (!$(".ui-dialog-buttonset")[0]) return setTimeout(() => tryAdd(), 500);
  362.                 $(".ui-dialog-buttonset")[0].appendChild(button)
  363.             }
  364.  
  365.             tryAdd();
  366.         });
  367.     });
  368.     Modules.registerModule("ForumMessageHistory", function() {
  369.         if (!PageAPI.isForumTopic()) return;
  370.  
  371.         DB.init();
  372.  
  373.         // временный костыль
  374.         window._pushHistory = function(msg) {
  375.             if (!DB.db) return setTimeout(() => window._pushHistory(msg), 1000);
  376.  
  377.             const text = PageAPI.getMessageHTML(msg);
  378.             const id = PageAPI.getMessageId(msg);
  379.  
  380.             DB.getMessageHistory(id, function(history) {
  381.                 if (history[history.length - 1] === text) return;
  382.  
  383.                 DB.pushQueue(id, PageAPI.getMessageHTML(msg));
  384.             });
  385.         }
  386.  
  387.         PageAPI.appendForumMessage = Injector.before(PageAPI.appendForumMessage, function(msg) {
  388.             window._pushHistory(msg);
  389.  
  390.             PageAPI.appendHistoryBtn(msg);
  391.         });
  392.  
  393.         PageAPI.getForumMessages().forEach(function(msg) {
  394.             window._pushHistory(msg);
  395.  
  396.             PageAPI.appendHistoryBtn(msg);
  397.         });
  398.  
  399.         window.editHistory = function(id) {
  400.             ShowLoading();
  401.  
  402.             DB.getMessageHistory(id, function(history) {
  403.                 HideLoading();
  404.  
  405.                 history.unshift("");
  406.  
  407.                 PageAPI.popup(
  408.                     "История редактирования",
  409.                     "<div style='overflow-y: scroll; height:400px;'>" + history.join("<hr>") + "</div>",
  410.                     {
  411.                         "Ясно": function() {
  412.                             $("#dlepopup").remove();
  413.                         }
  414.                     }
  415.                 );
  416.             });
  417.         }
  418.  
  419.         function tryQueue() {
  420.             if (DB.db) DB.processQueue();
  421.            
  422.             setTimeout(() => tryQueue(), 1000);
  423.         }
  424.  
  425.         tryQueue();
  426.     });
  427.     Modules.registerModule("ForumMessagesUpdater", function() {
  428.         if (!PageAPI.isForumTopic()) return;
  429.  
  430.         Notification.requestPermission();
  431.  
  432.         let currentPage = null;
  433.         let editing = null;
  434.  
  435.         function getNewMessages(cb) {
  436.             $.ajax({
  437.                 success: function(content) {
  438.                     cb({
  439.                         messages: PageAPI.getForumMessages(content),
  440.                         page: PageAPI.getForumPage(content)
  441.                     });
  442.                 }
  443.             });
  444.         }
  445.  
  446.         function tick() {
  447.             const current = PageAPI.getForumMessages();
  448.  
  449.             getNewMessages(function(actual) {
  450.                 if (current.length !== actual.messages.length) {
  451.                     actual.messages.slice(current.length).forEach(function(msg) {
  452.                         PageAPI.appendForumMessage(msg);
  453.  
  454.                         const info = PageAPI.getMessageInfo(msg);
  455.  
  456.                         let notification = new Notification(info.username, {
  457.                             body: info.text,
  458.                             icon: info.avatar
  459.                         });
  460.  
  461.                         setTimeout(() => notification.close(), 3000);
  462.                     });
  463.                 }
  464.  
  465.                 current.forEach(function(c, i) {
  466.                     if (c.getAttribute("id").endsWith(editing)) return;
  467.  
  468.                     if ($(".EditMsgView", $(c)).text() !== $(".EditMsgView", $(actual.messages[i])).text()) {
  469.                         if (window._pushHistory) {
  470.                             window._pushHistory(actual.messages[i]);
  471.                             PageAPI.appendHistoryBtn(actual.messages[i]);
  472.                         }
  473.  
  474.                         $("#" + c.getAttribute("id")).html(actual.messages[i].innerHTML);
  475.                     }
  476.                 });
  477.  
  478.                 if (currentPage !== null && currentPage !== actual.page) {
  479.                     currentPage = actual.page;
  480.  
  481.                     PageAPI.popup("Опа!", "Появилась новая страница!", {
  482.                         "Перейти": function() {
  483.                             window.location.href = window.location.href.replace("page-" + (actual.page - 1), "page-" + actual.page);
  484.                         }
  485.                     });
  486.  
  487.                     new Notification("Новая страница!", {
  488.                         body: "На форуме появилась новая страница"
  489.                     });
  490.                 }
  491.  
  492.                 if (currentPage === null) currentPage = actual.page;
  493.             });
  494.         }
  495.  
  496.         setInterval(() => tick(), 2000);
  497.  
  498.         // Inject
  499.         window.MsgEdit = Injector.before(window.MsgEdit, (id) => editing = id);
  500.         window.MsgEditSave = Injector.before(window.MsgEditSave, () => editing = null);
  501.         window.MsgEditCancel = Injector.before(window.MsgEditCancel, () => editing = null);
  502.  
  503.         // Redefine default functions
  504.         window.doAddMessage = function() {
  505.             var a = document.getElementById("message_add_form");
  506.             if (a.text_msg.value == "") {
  507.                 Alert_popup(lang[0][29][6], lang[0][23][0]);
  508.                 return false
  509.             }
  510.             if (a.recaptcha_response_field) {
  511.                 var b = Recaptcha.get_response();
  512.                 var c = Recaptcha.get_challenge()
  513.             } else if (a.question) {
  514.                 var b = a.question.value;
  515.                 var c = a.question_sec.value
  516.             } else {
  517.                 var b = "";
  518.                 var c = ""
  519.             }
  520.             Ajax_Loading("");
  521.             var d = new Array;
  522.             $("#message_add_form input[class='marker_file_ajax']").each(function(a, b) {
  523.                 d.push($(b).val())
  524.             });
  525.             if (forum_cpu) {
  526.                 var e = dle_root + forum_path + "/add/" + a.topict_id.value + "/post"
  527.             } else {
  528.                 var e = dle_root + "index.php?do=" + forum_path + "&action=newpost&id=" + a.topict_id.value + "&param=post"
  529.             }
  530.             $.post(e, {
  531.                 text_msg: a.text_msg.value,
  532.                 topic_id: a.topict_id.value,
  533.                 recaptcha_response_field: b,
  534.                 recaptcha_challenge_field: c,
  535.                 id_file: d
  536.             }, function(b) {
  537.                 Ajax_close("");
  538.                 if (b.param == 0) {
  539.                     Alert_popup(b.data, lang[0][23][0]);
  540.                     return false
  541.                 }
  542.                 setElementForum()
  543.                 $("#text_msg").val("");
  544.             }, "json");
  545.         }
  546.     });
  547.     Modules.registerModule("MultiAccount", function() {
  548.         $(".loginname").append(" <a href='#' style='color: #eee; font-size: 12px;' title='Мультиаккаунт' onclick='multiaccount(); return false;'>[+]</a>")
  549.  
  550.         if (!localStorage.getItem("accounts")) localStorage.setItem("accounts", "[]");
  551.  
  552.         function getAccounts() {
  553.             return JSON.parse(localStorage.getItem("accounts"));
  554.         }
  555.  
  556.         function addAccount(login, password) {
  557.             let accounts = getAccounts();
  558.             accounts.push({ login: login, password: password });
  559.             localStorage.setItem("accounts", JSON.stringify(accounts));
  560.         }
  561.  
  562.         function removeAccount(login) {
  563.             let accounts = getAccounts();
  564.             accounts = accounts.filter(e => e.login !== login);
  565.             localStorage.setItem("accounts", JSON.stringify(accounts));
  566.         }
  567.  
  568.         window.loginMultiaccount = function(login) {
  569.             if (localStorage.getItem("_logout") !== "1") {
  570.                 localStorage.setItem("_logout", "do");
  571.                 localStorage.setItem("_queue_login", login);
  572.                 return window.location.href = "https://ru-minecraft.ru/index.php?action=logout";
  573.             }
  574.  
  575.             localStorage.removeItem("_logout");
  576.  
  577.             document.write("Вхожу в аккаунт (2)...");
  578.  
  579.             const qlogin = localStorage.getItem("_queue_login");
  580.  
  581.             const password = getAccounts().find(e => e.login === qlogin).password;
  582.  
  583.             PageAPI.login(qlogin, password, function(success) {
  584.                 if (success) return setTimeout(() => window.location.reload(), 1000);
  585.  
  586.                 PageAPI.popup("Ошибка", "Неверный логин или пароль");
  587.             });
  588.         }
  589.  
  590.         window.deleteMultiaccount = function(login) {
  591.             removeAccount(login);
  592.             window.requestAnimationFrame(() => window.multiaccount());
  593.         }
  594.  
  595.         window.addMultiaccount = function() {
  596.             let page = "<div style='display: block; vertical-align: middle; border-bottom: solid #ddd 2px;'>";
  597.             page += "<img style='vertical-align: middle;' src='https://ru-minecraft.ru/templates/ru-minecraft/images/alert.png' />";
  598.             page += "<span style='vertical-align: middle;'>Пароли хранятся локально без какого либо шифрования</span><br>";
  599.             page += "</div><br>";
  600.  
  601.             // TODO move to html
  602.             page += "<input style='width: 520px; border: none; outline: none; font-size: 16px;' type='text' id='ma-login' placeholder='Логин'><br><br>";
  603.             page += "<input style='width: 520px; border: none; outline: none; font-size: 16px;' type='password' id='ma-password' placeholder='Пароль'>";
  604.  
  605.             PageAPI.popup("Добавить мультиаккаунт", page, {
  606.                 "Отмена": function() {
  607.                     window.requestAnimationFrame(() => window.multiaccount());
  608.                 },
  609.                 "Добавить": function() {
  610.                     const login = $("#ma-login").val();
  611.                     const password = $("#ma-password").val();
  612.  
  613.                     addAccount(login, password);
  614.                     window.requestAnimationFrame(() => window.multiaccount());
  615.                 }
  616.             });
  617.         }
  618.  
  619.         window.multiaccount = function() {
  620.             let page = "<button onclick='addMultiaccount();'>Добавить</button><hr>";
  621.  
  622.             getAccounts().forEach(function(account, i) {
  623.                 page += "<b>" + account.login + "</b> | ";
  624.                 page += "<button onclick=\"loginMultiaccount('" + account.login + "');\">Войти</button> |";
  625.                 page += "<button onclick=\"deleteMultiaccount('" + account.login + "');\">Удалить</button>";
  626.                 page += "<br>";
  627.             });
  628.  
  629.             PageAPI.popup("Мультиаккаунт", page, {
  630.                 "Закрыть": function() {
  631.                     $("#dlepopup").remove();
  632.                 }
  633.             });
  634.         }
  635.     });
  636.     Modules.registerModule("OnlineNotification", function() {
  637.         if (!window.location.href.startsWith("https://ru-minecraft.ru/forum/")) return;
  638.  
  639.         $.getScript("https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js");
  640.  
  641.         Notification.requestPermission();
  642.  
  643.         let current = PageAPI.getOnline();
  644.  
  645.         function tick() {
  646.             $.ajax({
  647.                 success: function(body) {
  648.                     const actual = PageAPI.getOnline(body);
  649.  
  650.                     const joined = _.difference(actual, current);
  651.  
  652.                     joined.forEach(function(username) {
  653.                         PageAPI.getUserInfo(username, function(info) {
  654.                             let notification = new Notification(username + " онлайн", {
  655.                                 icon: info.avatar
  656.                             });
  657.  
  658.                             setTimeout(() => notification.close(), 2000);
  659.                         });
  660.                     });
  661.  
  662.                     current = actual;
  663.                 }
  664.             });
  665.         }
  666.  
  667.         setInterval(() => tick(), 4000);
  668.     });
  669.     Modules.registerModule("ReleaseChecker", function() {
  670.         if (localStorage.getItem("lastChecked") === null || localStorage.getItem("lastChecked") + 600000 < Date.now()) {
  671.             $.ajax({
  672.                 url: "https://api.github.com/repos/yioyo3/ruminepp/releases",
  673.                 success: function(result) {
  674.                     if (result[0].tag_name === RMPPVersion || result[0].tag_name === localStorage.getItem("lastVersion"))
  675.                         return;
  676.  
  677.                     localStorage.setItem("lastVersion", result[0].tag_name);
  678.                     localStorage.setItem("lastChecked", Date.now());
  679.  
  680.                     PageAPI.popup("Новая версия RuMine++", "Появилась новая версия RuMine++ <b>" + result[0].tag_name + "</b>", {
  681.                         "Подробнее": function() {
  682.                             window.location.href = "https://github.com/yioyo3/ruminepp/releases";
  683.                         }
  684.                     });
  685.                 }
  686.             });
  687.         }
  688.     });
  689.     Modules.registerModule("RuMinePP", function() {
  690.         const container = $(".loginset")[1];
  691.         let rmppSettings = document.createElement("a");
  692.  
  693.         rmppSettings.href = "#";
  694.         rmppSettings.onclick = function() {
  695.             PageAPI.popup("Настройки RuMine++", HTML.get("settings.html"), {
  696.                 "Применить": function() {
  697.                     Array.from($(".rmppSetting")).forEach(e => localStorage.setItem(e.getAttribute("id") + "_enabled", e.checked ? "1" : "0"));
  698.                     localStorage.setItem("emoticons_urls", $("#CustomEmoticons_urls").val());
  699.                     window.location.reload();
  700.                 }
  701.             });
  702.  
  703.             $("#CustomEmoticons_urls").val(localStorage.getItem("emoticons_urls") || "");
  704.             $("#CustomEmoticons_urls").prop("disabled", localStorage.getItem("CustomEmoticons_enabled") === "0");
  705.             Array.from($(".rmppSetting")).forEach(e => e.checked = localStorage.getItem(e.getAttribute("id") + "_enabled") !== "0");
  706.  
  707.             return false;
  708.         }
  709.         rmppSettings.innerHTML = "Настройки RuMine++";
  710.  
  711.         container.appendChild(rmppSettings);
  712.     });
  713.  
  714.     HTML.register("settings.html", `<style>.ruminepp_logo{width:30%;position:relative;display:block;margin:0 auto;top:5px;opacity:.5}#checkboxes{width:100%;padding:0 30px}hr{border:2px dashed #82c3f3}input{opacity:0;z-index:-999}label{position:relative;display:inline-block;text-align:left;cursor:pointer;font-weight:500;padding:0 0 0 30px;height:20px;width:300px;float:left}.true_checkbox{width:15px;height:15px;position:relative;border:3px solid #71a9d2;border-radius:5px;margin:-21px 0;transition:border ease .4s;overflow:hidden;cursor:pointer}.fill{display:block;position:absolute;width:35px;height:35px;background:#9bd4ff;margin:15px 0 0 -30px;transform:rotate(45deg);transition:margin ease .5s}input:not(checked)+.true_checkbox{border:1.5px solid rgba(113,169,210,.3)}input:checked+.true_checkbox{border:3px solid #71a9d2}input:not(checked)+.true_checkbox>.fill{margin:15px 0 0 -30px}input:checked+.true_checkbox>.fill{margin:-7px}.more{text-decoration:none;color:#71a9d2;font-size:10px;transition:color ease .2s,visibility .5s,opacity .5s ease}.more:hover{text-decoration:none;color:#71a9d2}#spoiler{display:none;opacity:1;font-family:Consolas,'Droid Sans',Monaco,Lucida,sans-serif;transition:display ease .5s,opacity ease .5s}#spoiler textarea{border:1px dashed #71a9d2}.CustomEmoticons{width:155px}#CustomEmoticons_urls{outline:0}</style><img class=ruminepp_logo src=https://i.imgur.com/F9dywXu.png><br><hr style="border:.5px solid #91cdcf;width:100%"><span style="display:block;font-family:'Segoe UI',Arial,sans-serif;font-size:14px;user-select:none;background:url(https://i.imgur.com/ddIqSYY.png) repeat fixed center center"><div id=checkboxes><br><input class=rmppSetting id=RuMinePP type=checkbox><div class=true_checkbox><span class=fill></span></div><label for=RuMinePP>Включить RuMine++ (не убирать)</label><br><br><input class=rmppSetting id=ReleaseChecker type=checkbox><div class=true_checkbox><span class=fill></span></div><label for=ReleaseChecker>Проверять наличие новых релизов</label><br><br><input class=rmppSetting id=ForumMessagesUpdater type=checkbox><div class=true_checkbox><span class=fill></span></div><label for=ForumMessagesUpdater>Автообновление сообщений на форуме</label><br><br><input class=rmppSetting id=ForumMessageHistory type=checkbox><div class=true_checkbox><span class=fill></span></div><label for=ForumMessageHistory style=width:330px;font-size:13px>Сохранять историю редактирования сообщений</label><br><br><input class=rmppSetting id=CustomEmoticons type=checkbox><div class=true_checkbox><span class=fill></span></div><label for=CustomEmoticons class=CustomEmoticons>Кастомные эмотиконы</label><a class=more href="javascript:ShowOrHide('spoiler')">▼</a><div id=spoiler><br><textarea id=CustomEmoticons_urls placeholder="Ссылки на картинки для эмотиконов (с новой строки)"style=height:30px;width:450px;resize:none></textarea></div></div><br></span><script>$("#CustomEmoticons").click(function(){$(this).is(":checked")?($(".more").css({opacity:"1",visibility:"visible"}),$("#spoiler").css({opacity:"1",display:"none"})):($(".more").css({opacity:"0",visibility:"hidden"}),$("#spoiler").css({opacity:"1",display:"none"}))})</script>`)
  715. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement