Skip to content

Instantly share code, notes, and snippets.

@xPomaHx
Created March 27, 2019 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xPomaHx/83e70c45c43ce2614877e2c826ed3181 to your computer and use it in GitHub Desktop.
Save xPomaHx/83e70c45c43ce2614877e2c826ed3181 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name toster
// @description qwe
// @namespace toster
// @version 1.1
// @include https://toster.ru/questions/interesting
// @include https://toster.ru/my/feed_interesting
// ==/UserScript==
"use strict";
! function(win) {
if (window != window.top) return
win.addEventListener("load", function() {
var s = document.createElement('script');
document.body.appendChild(s);
s.src = 'https://code.jquery.com/jquery-3.2.1.js';
s.onload = function() {
(async () => {
var allPage = [];
for (let i = 1; i < 10; i++) {
allPage.push($.ajax("https://toster.ru/questions/interesting?page=" + i));
}
allPage = await Promise.all(allPage);
var allitem = [];
for (let page of allPage) {
var listitems = $(".page__body .content-list[role=content-list]", page);
$.merge(allitem, listitems.children("li"));
}
var digitreg = /[0-9]+/g;
allitem.sort((a, b) => {
var texta = $(a).find('.question__attrs li:nth-child(3) .question__views-count').html()
var textb = $(b).find('.question__attrs li:nth-child(3) .question__views-count').html()
var podpisa = new RegExp(digitreg).exec(texta);
var podpisb = new RegExp(digitreg).exec(textb);
if (+podpisa[0] > +podpisb[0]) {
return -1;
} else {
return 1;
}
});
$(".page__body .content-list[role=content-list]").html("");
$(".page__body .content-list[role=content-list]").append(allitem);
var vievedList = [];
if (localStorage.vievedList) {
vievedList = JSON.parse(localStorage.vievedList);
};
$(".page__body .content-list[role=content-list]>li").each((i, el) => {
var cros = $("<div class=disTitlle>x</div>");
cros.css({
position: "absolute",
top: "0",
right: "-15px",
width: "30px",
height: "30px",
fontSize: "30px",
lineHeight: "25px",
textAlign: "center",
color: "blue",
background: "red",
cursor: "pointer",
});
$(el).append(cros.clone());
for (name of vievedList) {
var title = $(el).find(".question__title a").html();
if (name === title) {
$(el).remove();
}
};
});
$(document).on("click", ".disTitlle", function(e) {
var art = $(e.currentTarget).parent("li");
var title = art.find(".question__title a").html();
art.remove();
vievedList.push(title);
localStorage.vievedList = JSON.stringify(vievedList);
});
})();
}
}, false);
}(typeof unsafeWindow == 'undefined' ? window : unsafeWindow);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment