Mirrorek+

Narzędzie do mirrorowania wpisów i znalezisk.

  1. // ==UserScript==
  2. // @name Mirrorek+
  3. // @namespace http://www.wykop.pl/
  4. // @version 1.0.0
  5. // @description Narzędzie do mirrorowania wpisów i znalezisk.
  6. // @author http://www.wykop.pl/ludzie/rok2015/
  7. // @match http://*.wykop.pl/wpis/*
  8. // @match http://*.wykop.pl/moj/*
  9. // @match http://*.wykop.pl/link/*
  10. // @require https://gf.qytechs.cn/scripts/7223-moment-js/code/Momentjs.js?version=29866
  11. // @require https://gf.qytechs.cn/scripts/7243-spin-js/code/Spinjs.js?version=29979
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15.  
  16. (function() {
  17.  
  18. //////
  19.  
  20. // Jeżeli nie chcesz dodawać automatycznie mirrora w powiązane znaleziska zmień poniżej true na false i zapisz.
  21.  
  22. var automatyczne_Powiazane = true;
  23.  
  24. /////
  25.  
  26.  
  27.  
  28. //settings
  29. moment.locale("pl");
  30. var entryNumber = parseInt(localStorage.getItem('mirrorek.Number')) || 0; //liczba wpisów
  31. var entryCounter = parseInt(localStorage.getItem('mirrorek.Counter')) || 0; //licznik localstorage
  32. var thisLink = $('#itemsStream > li > div.wblock.lcontrast.dC > div > div.author.ellipsis > a:last-of-type').attr('href'); //link wpisu
  33.  
  34.  
  35. // dane o wpisie ładowane do tablicy
  36. function entryData() {
  37. var arrayLocaldata = new Array();
  38. arrayLocaldata[0] = $('.showProfileSummary:first > b').text(); //nick
  39. arrayLocaldata[1] = $('.showProfileSummary:first > b').css('color'); //kolor nicka
  40. arrayLocaldata[2] = $('#itemsStream > li > div.wblock.lcontrast.dC > a.profile > img').attr('data-original'); //avatar
  41. arrayLocaldata[3] = $('#itemsStream > li > div.wblock.lcontrast.dC > div > div.author.ellipsis > a:last-of-type > small > time').attr('title'); //data dodania wpisu
  42. arrayLocaldata[4] = $('#itemsStream > li > div.wblock.lcontrast.dC > div > div.author.ellipsis > a:last-of-type').attr('href'); //link do wpisu
  43. arrayLocaldata[5] = $('#itemsStream > li > div.wblock.lcontrast.dC').data("id"); //id wpisu
  44. arrayLocaldata[6] = $('#itemsStream > li:nth-child(1) > div > div > div.text > p').html(); //treść wpisu
  45. arrayLocaldata[7] = $('a.profile > img').attr('class'); // kolor paska
  46. arrayLocaldata[8] = $('#itemsStream > li > div.wblock.lcontrast.dC > div > div.text > div.media-content > a').attr('href') || 0; //link do zdjęcia/video/gifa
  47.  
  48. arrayLocaldataJSON = JSON.stringify(arrayLocaldata); // tablica do JSON
  49. };
  50.  
  51.  
  52.  
  53.  
  54. //sprawdzenie dostępności mirrora na web.history
  55. function title() {
  56. var requestLink = encodeURI("http://archive.org/wayback/available?url="+thisLink+"&callback=?");
  57. $.getJSON(requestLink, function(result) {
  58. $("li.mirror > a").prop('title','Brak mirrora');
  59. $("li.mirror > a> i").css("color","#F62817");
  60. available = result.archived_snapshots.closest.available;
  61. timestamp = result.archived_snapshots.closest.timestamp;
  62. ago = moment(timestamp + 0000, "YYYYMMDDhhmmss Z").fromNow();
  63. if (available == true) {
  64. $("li.mirror > a").prop('title','ostatni mirror: '+ago);
  65. $("li.mirror > a> i").css("color","#85BB65");
  66. };
  67.  
  68. });
  69. };
  70.  
  71.  
  72. //zapisywanie Wpisu
  73. function saveMirror() {
  74. Dim();
  75. entryData();
  76. var saveLink = "http://web.archive.org/save/" + thisLink;
  77. console.log('data '+arrayLocaldataJSON);
  78. $.ajax({
  79. url: saveLink,
  80. type: "GET",
  81. crossDomain: true,
  82. beforeSend: function(xhr){xhr.setRequestHeader('Access-Control-Allow-Origin', '*');},
  83. success: console.log('sukces'),
  84. complete: function(data) {
  85. entryCounter++;
  86. localStorage.setItem('mirrorek.link'+entryCounter+'n', arrayLocaldataJSON );
  87. localStorage.setItem('mirrorek.Counter', entryCounter);
  88. entryNumber++;
  89. localStorage.setItem('mirrorek.Number', entryNumber);
  90. unDim();
  91. alert("Mirror wykonany");
  92. }
  93. });
  94.  
  95. };
  96.  
  97.  
  98.  
  99.  
  100.  
  101. if (document.location.pathname.match('/wpis/')) {
  102.  
  103. //tworzymy ikonkę mirrora we wpisie
  104. $('#itemsStream > li > div.wblock.lcontrast.dC > div > div.row.elements.actions > ul').append('<li class="mirror"><a href class="affect hide ajax"><i class="fa fa-flag-o"></i> mirror</a></li>');
  105. title();
  106.  
  107. //wywołanie zapisywania
  108. $("li.mirror > a").click(function() {
  109. saveMirror();
  110. });
  111.  
  112. };
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119. // dim background & spinner
  120. var opts = {lines: 13, length: 13, width: 6, radius: 19, corners: 1, rotate: 0, direction: 1, color: '#000', speed: 1, trail: 64, shadow: true, hwaccel: false, className: 'spinner', zIndex: 2e9, top: '50%', left: '50%'};
  121. var spinner;
  122.  
  123. function Dim() {
  124. $('body').append('<div id="spinOverlay" class="overlay" style="display: block;"></div><div id="spinnerek" class="lightbox" style="display: block; top: 300px; left: 0px;"></div>');
  125. var target = document.getElementById('spinnerek');
  126. spinner = new Spinner(opts).spin(target);
  127. };
  128.  
  129. function unDim() {
  130. spinner.stop();
  131. $('#spinOverlay').remove();
  132. $('spinnerek').remove();
  133. };
  134.  
  135.  
  136.  
  137.  
  138.  
  139.  
  140.  
  141. // tworzenie menu "mirrorek"
  142. if (document.location.pathname.match('/moj/')) {
  143. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:nth-child(3) > li:nth-child(3)').after('<li id=mir><a href="http://www.wykop.pl/moj/mirrorek"><span>mirrory <b>('+entryNumber+')</b></span></a></li>');
  144. };
  145.  
  146.  
  147.  
  148.  
  149.  
  150.  
  151.  
  152.  
  153. //zakładka mirrorek - lista wpisów
  154. if (document.location.pathname.match('/mirrorek/')) {
  155. //menu
  156. $('ul:nth-child(3) > li.active').removeClass('active');
  157. $('#mir').addClass('active');
  158. $('.entry.iC ').remove();
  159. $('.link.iC ').remove();
  160. $('div.wblock ').remove();
  161.  
  162. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:nth-child(2) > li:nth-child(1)').removeClass('active').html('<a href="#" id="zapisz" class="ajax">zapisz</a>'); //zakładka zapisz
  163. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block > ul:nth-child(2) > li:nth-child(2)').removeClass('active').html('<a href="#" id="import" class="ajax">importuj</a>'); //zakładka importuj
  164.  
  165. //wypisuje listę mirrów
  166. x = 1
  167. while (x <= entryCounter) {
  168. var getArray = JSON.parse(localStorage.getItem('mirrorek.link'+x+'n')) || 0;
  169. console.log(x);
  170. if (getArray == 0) {
  171. x++;
  172. } else {
  173. var author = getArray[0]; //autor
  174. var color = getArray[1]; //kolor nicka
  175. var avatar = getArray[2]; //avatar
  176. var addDate = getArray[3]; //data wpisu
  177. var link = getArray[4]; //link do wpisu
  178. var idWpis = getArray[5]; //id wpisu
  179. var paragraf = getArray[6]; //treść wpisu
  180. var avatarClass = getArray[7]; //kolor paska
  181. var mediaWpis = getArray[8]; //załącznik wpisu
  182. var linkToMirror = "http://web.archive.org/web/"+link; //link do mirrora
  183. var linkToAll = "http://web.archive.org/web/*/"+link; //link do wszystkich
  184. var timeMoment = moment(addDate, "YYYY-MM-DD HH:mm:ss").fromNow();
  185.  
  186. // dodawanie załącznika do wpisu
  187. var divMedia;
  188. if (mediaWpis === undefined) {
  189. divMedia = "";
  190. }
  191. else if (mediaWpis !== 0 ) {
  192. divMedia = '<div class="media-content hide-image" data-type="entry"><a href="'+mediaWpis+'" data-open="1" class="ajax" data-ajaxurl="http://www.wykop.pl/ajax2/embed/html/type/entry/id/'+idWpis+'/">[zobacz media]</a></div>'
  193. }
  194. else {
  195. divMedia = "";
  196. }
  197.  
  198.  
  199. //ładowanie wpisu
  200. $('#site > div > div.grid.m-reset-float > div > div.nav.bspace.rbl-block').after('<ul id="itemsStream" class="comments-stream"><li class="entry iC"><div class="wblock lcontrast dC " data-id="'+idWpis+'" data-type="entry"><a name="" style="position: relative; top: -120px">&nbsp;</a><a class="profile" href="http://www.wykop.pl/ludzie/'+author+'/" title=""><img class="'+avatarClass+'" alt="" src="'+avatar+'"></a><div><div class="author ellipsis "><a class="showProfileSummary" href="http://www.wykop.pl/ludzie/'+author+'/" title=""><b style="color:'+color+'">'+author+' </b></a><a href="'+link+'"><small class="affect"><time title="'+addDate+'" pubdate="">'+timeMoment+'</time></small></a><small class="affect"></small></div><div class="text"><p>'+paragraf+'</br>'+divMedia+'</p></div><div class="row elements actions"><a href="'+linkToMirror+'" class="affect hide"><i class="fa fa-chain"></i> Ostatni</a><a href="'+linkToAll+'" class="affect hide"><i class="fa fa-chain"></i> Wszystkie</a><a href="'+link+'" class="affect hide"><i class="fa fa-chain"></i> Wykop</a><a href=" " class="affect hide ajax" id="mirrorek.link'+x+'n"><i class="fa fa-trash-o"></i> Usuń</a></div></div></div></div></li></ul>');
  201. x++;
  202. };
  203. };
  204.  
  205.  
  206.  
  207. // usuwanie wpisu z localstorage, zmiana liczby mirrorów
  208. $('a.affect.hide.ajax').click(function() {
  209. localStorage.removeItem($(this).attr('id'));
  210. $(this).closest('.comments-stream').hide();
  211. entryNumber--;
  212. localStorage.setItem('mirrorek.Number', entryNumber);
  213. });
  214.  
  215.  
  216.  
  217. // naprawianie spoilerów w /mirrorek/
  218. $('.showSpoiler').click(function() {
  219. $(this).css('display','none');
  220. $(this).next().addClass('spoilerBody').css('display','inline');
  221. });
  222.  
  223.  
  224.  
  225.  
  226. //zapisz mirrory do pliku
  227. $('#zapisz').click(function() {
  228. text = [];
  229. var x = 1;
  230. while (x <= entryCounter) {
  231. var linkNumber = 'mirrorek.link'+x+'n';
  232. var storageItem = JSON.parse(localStorage.getItem('mirrorek.link'+x+'n')) || 0;
  233. if (entryCounter == 0) {
  234. alert("brak wpisów");
  235. return false;
  236. } else if (storageItem == 0) {
  237. x++;
  238. }
  239. else {
  240. text[x] = [linkNumber, storageItem];
  241. console.log(text[x]);
  242. console.log("długość tablicy "+text.length);
  243. x++;
  244. }
  245. };
  246. textJSON = JSON.stringify(text);
  247. this.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(textJSON));
  248. this.setAttribute('download', "mirrorek-save.json");
  249. $(this).removeClass('ajax');
  250. });
  251.  
  252.  
  253.  
  254. // importowanie wpisów z pliku, nie do końca wiem co tu sie dzieje
  255. $('#import').click(function() {
  256. $('body').prepend('<div id="violationContainer"><div class="overlay" style="display: block;"></div><div id="zgloszenie" class="normal m-set-fullwidth m-reset-top m-reset-margin m-reset-left" style="height: 300px; width: 400px"><div style="position: absolute; top: 4%; left: 96%;"><a href="#" title="zamknij" class="fright close"><span class="icon inlblk mini closepreview"><i class="fa fa-times"></i></span></a></div><input type="file" id="input" style="position: absolute; left: 35%; top: 50%;"/></div></div>');
  257. function readSingleFile(e) {
  258. var file = e.target.files[0];
  259. if (!file) {
  260. return;
  261. }
  262. var reader = new FileReader();
  263. reader.onload = function(e) {
  264. var contents = e.target.result;
  265. displayContents(contents);
  266. };
  267. reader.readAsText(file);
  268. };
  269.  
  270. function displayContents(contents) {
  271. var entryNumber = 0;
  272. localStorage.setItem('mirrorek.Number', entryNumber);
  273.  
  274. listaJSON = JSON.parse(contents);
  275. var x = 1;
  276. while (x <= listaJSON.length-1) {
  277. if (listaJSON[x] == null) {
  278. x++;
  279. }
  280. else {
  281. var klucz = listaJSON[x][0];
  282. console.log("klucz "+klucz);
  283. var wartosc = JSON.stringify(listaJSON[x][1]);
  284. localStorage.setItem(klucz, wartosc);
  285. console.log("liczkik = "+x);
  286. entryNumber++;
  287. localStorage.setItem('mirrorek.Number',entryNumber);
  288. x++;
  289. }
  290. localStorage.setItem('mirrorek.Counter', x);
  291. };
  292. if (x = listaJSON.length-1) {
  293. $('#violationContainer').remove();
  294. location.reload();
  295. }
  296.  
  297. };
  298.  
  299. document.getElementById('input')
  300. .addEventListener('change', readSingleFile, false);
  301. });
  302. };
  303.  
  304.  
  305.  
  306. // mirrorowanie znalezisk
  307. if (document.location.pathname.match('/link/')) {
  308.  
  309. //tworzymy przycisk
  310. $('#site > div > div.grid.m-reset-float > div > div:nth-child(1) > div.bspace > div > div.lcontrast.m-reset-float.m-reset-margin > div.row.elements.actions > ul').append('<li><a href="#" class="affect" id="mirror"><i class="fa fa-flag-o"></i> mirror</a></li>');
  311.  
  312. var linkZnaleziskoSave = "http://web.archive.org/save/" + $('div.fix-tagline > span:nth-child(2) > a').attr('href');
  313. var linkZnalezisko = "http://web.archive.org/web/" + $('div.fix-tagline > span:nth-child(2) > a').attr('href');
  314.  
  315. $('#mirror').click(function() {
  316. Dim();
  317. $.ajax({
  318. url: linkZnaleziskoSave,
  319. type: "GET",
  320. crossDomain: true,
  321. beforeSend: function(xhr){xhr.setRequestHeader('Access-Control-Allow-Origin', '*');},
  322. success: console.log('link zapisany na web.history.org'),
  323. complete: function(data) {
  324. console.log("sukces"+data);
  325. if (automatyczne_Powiazane == true) {
  326.  
  327. (function sendPowiazane() {
  328.  
  329. var request;
  330. var params;
  331.  
  332. request = new XMLHttpRequest();
  333.  
  334. var token = $('#__token').val();
  335. var title = "Mirror (web.archive.org) by #mirrorek"
  336. var url = linkZnalezisko;
  337. var link_id = $('input[name="trackback[link_id]"').val();
  338. var action = $('#addRelatedForm > form').attr('action');
  339.  
  340. params = "&__token=" + token+ "&trackback[title]=" + title + "&trackback[url]=" + url + "&trackback[link_id]=" + link_id;
  341. console.log(params);
  342.  
  343. request.open("POST", action, true);
  344.  
  345. request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");
  346.  
  347. request.send(params);
  348. request.responseType = "document";
  349.  
  350. request.onreadystatechange = function() {
  351. console.log(request.status);
  352. console.log(request.readyState);
  353. if(request.readyState == 4 && request.status == 200) {
  354. console.log(request.responseXML);
  355. (function() {
  356. if ($(request.responseXML).find('#site > div > div.grid.m-reset-float > div > div > div > div > div.row.buttons.text-right > div > a').attr('href') == "http://www.wykop.pl/") {
  357. unDim();
  358. alert('Przekroczony limit dodawania powiązanych, error');
  359. }
  360. else if ($(request.responseXML).find('#realted-add-form > fieldset:nth-child(1) > div').hasClass('error') == true) {
  361. unDim();
  362. alert('Link o tym adresie już istnieje, ale mirror został zaktualizowany');
  363. }
  364. else {
  365. unDim();
  366. alert('Mirror zapisany');
  367. location.reload();
  368. }
  369. })();
  370. }
  371. };
  372.  
  373. })();
  374. };
  375.  
  376. }
  377. });
  378.  
  379. });
  380. }
  381.  
  382. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址