Improve logsoku for smart phone

display image directly, add links that show a certain accout of floor

  1. // ==UserScript==
  2. // @name Improve logsoku for smart phone
  3. // @description display image directly, add links that show a certain accout of floor
  4. // @include https://www.logsoku.com/*
  5. // @include https://sp.logsoku.com/*
  6. // @include http://*.2ch.*
  7. // @author yechenyin
  8. // @version 0.92.4
  9. // @namespace https://greasyfork.org/scripts/3497
  10. // ==/UserScript==
  11.  
  12.  
  13. /**************************以下参数可自定义修改**************************/
  14.  
  15. //图片显示默认缩放比例
  16. var percent = 0.5;
  17.  
  18. //图片显示最大高度(像素)
  19. var image_max_height = 420;
  20.  
  21. //图片显示最大宽度(像素)
  22. var image_max_width = 600;
  23.  
  24. //图片显示最小高度(像素)
  25. var image_min_height = 240;
  26.  
  27. //显示显示最小宽度(像素)
  28. var image_min_width = 320;
  29.  
  30. //弹出图片的原图,要取消此功能请将true改为false
  31. var popup_enable = true;
  32.  
  33. //点击图片后隐藏图片,要取消此功能请将true改为false
  34. var click_to_hide_image = true;
  35.  
  36.  
  37. //
  38. var phone_thread_comments = 334;
  39.  
  40. //
  41. var contain_floores = 250;
  42.  
  43. //
  44. var pc_searched_links_contain_comments = 500;
  45.  
  46. //
  47. var latest_floors = 150;
  48.  
  49. var block_floors_contain_blacklist_image = true;
  50.  
  51. var search_result_latest_floors = 15;
  52.  
  53. /****************************************************/
  54. if (!localStorage)
  55. alert('This browser does not support localStorage!');
  56. if (localStorage.last_read === undefined)
  57. localStorage.last_read = '';
  58. if (localStorage.filter === undefined)
  59. localStorage.filter = '';
  60. if (localStorage.blacklist_ids === undefined)
  61. localStorage.blacklist_ids = '';
  62. if (localStorage.blacklist_images === undefined)
  63. localStorage.blacklist_images = '';
  64. window.onerror = function(msg, url, num) {
  65. //alert(num+' '+msg);
  66. };
  67.  
  68. if (location.href.match("https://sp.logsoku.com/search")) {
  69. $('head').append($('<style>').text('iframe' + ' {display:none!important}'));
  70. for (var i = 0; i < $("a.search_thread_title").length; i++) {
  71. var thread = $("a.search_thread_title").eq(i);
  72. last_comment = thread.next().find(".res span").text().match(/\d+/)[0];
  73. var href = thread[0].href + "1-" + last_comment;
  74. var all_comments = $("<a>", {
  75. href: href
  76. });
  77. thread.next().find(".res span").wrap(all_comments);
  78.  
  79.  
  80. var time = thread.next().find(".date").text();
  81. time = time.replace(/\d{4}-/, "").replace(/:\d{2}\s/, " ");
  82. time = time.replace(/\d{4}-/, "").replace(/:\d{2}\s$/, " ");
  83. thread.next().find(".date").text(time);
  84.  
  85. }
  86.  
  87.  
  88. get_last_read("a.search_thread_title");
  89. // openDB().onsuccess = function(event){
  90. // var db = event.target.result;
  91. // var transaction = db.transaction(["read"],"readwrite");
  92. // var store = transaction.objectStore("read");
  93. //
  94. // for (var i=0; i<$("a.search_thread_title").length; i++) {
  95. // (function(i) {
  96. // var thread = $("a.search_thread_title").eq(i);
  97. // var url = thread[0].href.replace("https://sp.logsoku.com", "");
  98. // var request = store.get(url);
  99. // request.onsuccess = function(event){
  100. // if (event.target.result) {
  101. // var start = event.target.result.last + 1;
  102. // if (start >1000)
  103. // start = 1001;
  104. // var end = start + phone_thread_comments;
  105. // thread[0].href = url + start + "-" + end;
  106. // } else {
  107. // thread[0].href = url + "1-" + phone_thread_comments;
  108. // }
  109. // console.log(i + ":" + thread[0].href);
  110. // };
  111. // })(i);
  112. // }
  113. // };
  114. }
  115.  
  116.  
  117.  
  118. jQuery.fn.loaded = function(action) {
  119. var target = this;
  120. if ($(this.selector).length > 0) {
  121. console.log($(this.selector).length + ' ' + this.selector + " is loaded");
  122. setTimeout(function() {
  123. action();
  124. }, 300);
  125. } else
  126. setTimeout(function() {
  127. target.loaded(action);
  128. }, 100);
  129. };
  130.  
  131. jQuery.fn.handle = function() {
  132. this.each(function() {
  133. if (this.href && this.href.indexOf("http://l.moapi.net/") === 0) {
  134. this.href = this.href.replace("http://l.moapi.net/", '');
  135. this.href = this.href.replace(/\w*:?\/\//, "http://");
  136. }
  137. if (this.href && this.offsetTop > document.body.scrollTop - window.screen.height / 2 && this.offsetTop < document.body.scrollTop + window.screen.height * 3) {
  138. if (localStorage.blacklist_images && localStorage.blacklist_images.indexOf(this.href) > 0) {
  139. if (block_floors_contain_blacklist_image) {
  140. $(this).parent().prev().hide();
  141. $(this).parent().hide();
  142. }
  143. else
  144. $(this).hide();
  145. } else if (this.href.match(/\.(jpg|jpeg|bmp|gif|png|JPG|JPEG|BMP|GIF|PNG)(:orig)?$/) && localStorage.filter != "all_comments_hide_images") {
  146. console.log(this.href);
  147. $(this).replaceWith($("<img>", {
  148. src: this.href
  149. }));
  150. }
  151. }
  152. });
  153. };
  154.  
  155. if (location.href.indexOf("https://sp.logsoku.com/r/") === 0) {
  156. $('head').append($('<style>').text('iframe' + ' {display:none!important}'));
  157.  
  158. if (location.href[location.href.lastIndexOf("/") + 1] != "l")
  159. var first = parseInt($(".thread_2ch>dd").eq(0).attr("id").replace("comment_", ""));
  160. else
  161. var first = parseInt($(".thread_2ch>dd").eq(1).attr("id").replace("comment_", ""));
  162. var last = parseInt($(".thread_2ch>dd").last().attr("id").replace("comment_", ""));
  163. if (last > 1000)
  164. last = 1001;
  165. var amount = parseInt($(".navbar").prev().text().match(/^\d+/)[0]);
  166. if (amount > 1000)
  167. amount = 1000;
  168.  
  169. $(".pagination li").remove();
  170. var href = location.href.substring(0, location.href.lastIndexOf("/") + 1);
  171.  
  172. var link = null;
  173. if (first - phone_thread_comments >= 1)
  174. link = $("<a>", {
  175. text: "<",
  176. href: href + (first - phone_thread_comments).toString() + "-" + (first - 1).toString()
  177. });
  178. else if (first >= 1)
  179. link = $("<a>", {
  180. text: "<",
  181. href: href + "1" + "-" + (first - 1).toString()
  182. });
  183. if (link)
  184. $(".pagination ul").append(link.wrap($("<li>")));
  185.  
  186. for (var i = 0; i < amount / phone_thread_comments; i++) {
  187. link = $("<a>", {
  188. text: (i + 1).toString(),
  189. href: href + (i * phone_thread_comments + 1).toString() + "-" + (i * phone_thread_comments + phone_thread_comments).toString()
  190. });
  191. $(".pagination ul").append(link.wrap($("<li>")));
  192. }
  193.  
  194. var next_link = null;
  195. if (last + phone_thread_comments < amount)
  196. next_link = $("<a>", {
  197. text: ">",
  198. href: href + (last + 1).toString() + "-" + (last + phone_thread_comments).toString()
  199. });
  200. else if (last + 1 <= amount)
  201. next_link = $("<a>", {
  202. text: ">",
  203. href: href + (last + 1).toString() + "-" + amount
  204. });
  205. if (next_link)
  206. $(".pagination ul").append(next_link.wrap($("<li>")));
  207.  
  208. var filter_menu = $("<li>", {
  209. class: "dropdown open filter"
  210. });
  211. var innerHTML = "<a href='#' class='dropdown-toggle'>过滤<b class='caret'></b></a>";
  212. innerHTML += "<ul class='dropdown-menu filter-menu' style='display:none'>";
  213. innerHTML += "<li id='all_comments'><a>全部</a></li><li class='divider'></li>";
  214. innerHTML += "<li id='all_comments_hide_images'><a>不显示图片</a></li><li class='divider'></li>";
  215. innerHTML += "<li id='only_reply_and_links'><a>只含回复及链接</a></li><li class='divider'></li>";
  216. innerHTML += "<li id='only_links_and_images'><a>只含链接及图片</a></li><li class='divider'></li>";
  217. innerHTML += "<li id='only_images'><a>只含图片</a></li> </ul>";
  218. filter_menu.html(innerHTML);
  219. filter_menu.insertBefore($("ul.nav>li:last-child").eq(0));
  220.  
  221. $("li.filter>a").click(function() {
  222. $(this).next().toggle();
  223. });
  224.  
  225. filter_comments();
  226. $("ul.filter-menu").on("click", "li", function(filter) {
  227. localStorage.filter = this.id;
  228. filter_comments();
  229. });
  230.  
  231.  
  232. record_last_read();
  233. get_last_read("dd>a[href^='/']");
  234.  
  235.  
  236.  
  237.  
  238. $(".thread dt br").remove();
  239. $(".thread dt .nem, dt>b").remove();
  240. $(".thread dt").append($("<span>", {
  241. text: "block this ID",
  242. click: blockId
  243. }));
  244. $(".thread dt").append("&nbsp;&nbsp;");
  245. $(".thread dt").append($("<span>", {
  246. text: "block images blow",
  247. click: blockImages
  248. }));
  249. $(".thread dt").each(function() {
  250. var id = $(this).find("a[class^='id']").text();
  251. if (localStorage.blacklist_ids && localStorage.blacklist_ids.indexOf(id) > 0) {
  252. $(this).next().remove();
  253. $(this).remove();
  254. }
  255. });
  256.  
  257. $(".thread dd>a").handle();
  258. $(window).scroll(function() {
  259. $(".thread dd>a").handle();
  260. });
  261.  
  262.  
  263. $(".anchor_res>a").click(function() {
  264. $(this).parent().load(this.href + " .thread_2ch>dd");
  265. return false;
  266. });
  267.  
  268.  
  269.  
  270. $("#thread-recommend-list-display a").loaded(function() {
  271. var recommend = $("#thread-recommend-list-display");
  272. var title = $('h1.title').eq(0).text();
  273. if (title.indexOf('★') > 0)
  274. common = title.substring(0, title.indexOf('★'));
  275. else if (title.indexOf('☆') > 0)
  276. common = title.substring(0, title.indexOf('★'));
  277. else {
  278. var title1 = recommend.find("a").eq(0).text();
  279. var title2 = recommend.find("a").eq(1).text();
  280. for (i = 0; i < title1.length; i++)
  281. if (title2[i] != title1[i])
  282. break;
  283. common = title1.substring(0, i - 1);
  284. }
  285. console.log('query:' + common);
  286.  
  287. recommend.prepend($("<div>", {
  288. css: {
  289. display: "none"
  290. }
  291. }));
  292. recommend.children().first().load("https://sp.logsoku.com/search?q=" + common + " .search-list", function() {
  293. for (i = 0; i < recommend.find("li a").length; i++) {
  294. recommend.find("li a")[i].href = $(".search-list .column>a")[i].href;
  295. recommend.find("li a")[i].textContent = $(".search-list .column>a")[i].textContent;
  296. }
  297.  
  298. recommend.find("li").each(function() {
  299. if (location.href.match($(this).find("a")[0].href)) {
  300. $(this).css({
  301. 'border': '2px solid #AFAE93',
  302. 'border-top': '1px solid #AFAE93'
  303. });
  304. }
  305. });
  306.  
  307. get_last_read("#thread-recommend-list-display a");
  308. recommend.find("li a").each(function() {
  309. if (this.href.match(/\d+(?=-)/)[0] > 1000) {
  310. $(this).css({
  311. 'color': '#8F8E7D'
  312. });
  313. }
  314. });
  315.  
  316. });
  317. });
  318.  
  319. }
  320.  
  321.  
  322.  
  323. function get_last_read(links) {
  324. for (var i = 0; i < $(links).length; i++) {
  325. var thread = $(links)[i];
  326. var url = thread.href.replace("https://sp.logsoku.com", "");
  327. var index = -1;
  328. if (localStorage.last_read)
  329. index = localStorage.last_read.indexOf(url);
  330. if (index > 0) {
  331. var last_read = parseInt(localStorage.last_read.substr(index - 3, 3));
  332. if (last_read === 0)
  333. last_read = 1000;
  334. var start = last_read + 1;
  335. var end = start + phone_thread_comments;
  336. console.log(last_read + ' is read last time for ' + url);
  337.  
  338. thread.href = url + start + "-" + end;
  339. } else {
  340. thread.href = url + "1-" + phone_thread_comments;
  341. }
  342. console.log(i + "::" + thread.href);
  343. }
  344. }
  345.  
  346.  
  347. function record_last_read() {
  348. var url = location.href.replace("https://sp.logsoku.com", "");
  349. url = url.substring(0, url.lastIndexOf("/") + 1);
  350. var last_read = $(".thread_2ch>dt strong").last().text();
  351. if (last_read.length == 1)
  352. last_read = '00' + last_read;
  353. if (last_read.length == 2)
  354. last_read = '0' + last_read;
  355. if (last_read.length == 4)
  356. last_read = '000';
  357. console.log(last_read + ' is read for' + url);
  358.  
  359. var index = -1;
  360. if (localStorage.last_read)
  361. index = localStorage.last_read.indexOf(url);
  362. if (index < 0) {
  363. localStorage.last_read += last_read + url + "\n";
  364. } else {
  365. localStorage.last_read = localStorage.last_read.substring(0, index - 4) + last_read + localStorage.last_read.substr(index);
  366. }
  367. console.log('last read:' + localStorage.last_read);
  368.  
  369. // openDB().onsuccess = function(event){
  370. // var db = event.target.result;
  371. // var transaction = db.transaction(["read"],"readwrite");
  372. // transaction.oncomplete = function(event) {
  373. // console.log("Success");
  374. // };
  375. // transaction.onerror = function(event) {
  376. // alert("Error");
  377. // };
  378. //
  379. //
  380. //
  381. // var store = transaction.objectStore("read");
  382. // var request = store.get(url);
  383. // request.onsuccess = function(event){
  384. // if (!request.result) {
  385. // console.log("Adding : "+ url + " : " + last_read);
  386. // store.add({url: url, last: parseInt(last_read)});
  387. // } else {
  388. // console.log("Updating : "+event.target.result.last + " to " + last_read);
  389. // request.result.last = parseInt(last_read);
  390. // store.put(request.result);
  391. // }
  392. // };
  393. //
  394. // };
  395. //
  396. }
  397.  
  398. function openDB() {
  399. var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB;
  400. if (!indexedDB)
  401. console.log("你的浏览器不支持IndexedDB");
  402.  
  403. var request = indexedDB.open("2chDB", 1);
  404. var db;
  405. request.onerror = function(event) {
  406. alert("打开DB失败" + event);
  407. };
  408. request.onupgradeneeded = function(event) {
  409. console.log("Upgrading");
  410. db = event.target.result;
  411. var objectStore = db.createObjectStore("read", {
  412. keyPath: "url"
  413. });
  414. objectStore.createIndex("last", "last", {
  415. unique: false
  416. });
  417. };
  418. return request;
  419. }
  420.  
  421. function blockId() {
  422. var id = $(this).parent().find("a[class^='id']").text();
  423. localStorage.blacklist_ids += id + ",";
  424.  
  425. $("dt").each(function() {
  426. var id = $(this).find("a[class^='id']").text();
  427. if (localStorage.blacklist_ids.indexOf(id) > 0) {
  428. $(this).next().hide();
  429. $(this).hide();
  430. }
  431. });
  432. }
  433.  
  434. function blockImages() {
  435. var images = $(this).parent().next().find("img");
  436. localStorage.blacklist_images += images[0].src + " ";
  437.  
  438. $("dt").each(function() {
  439. var images = $(this).next().find("img");
  440. for (i = 0; i < images.length; i++) {
  441. if (localStorage.blacklist_images.indexOf(images[i].src) > 0) {
  442.  
  443. if (block_floors_contain_blacklist_image) {
  444. $(this).next().hide();
  445. //$(this).hide();
  446. break;
  447. } else
  448. $(images[i]).hide();
  449. }
  450. }
  451. });
  452. }
  453.  
  454. function filter_comments() {
  455. if (this.nodeName == "li" && this.id !== undefined)
  456. localStorage.filter = this.id;
  457.  
  458. $("ul.filter-menu>li").each(function() {
  459. if (this.id == localStorage.filter)
  460. $(this).css("background", "#d8edff");
  461. else
  462. $(this).css("background", "#fff");
  463. });
  464. $("ul.filter-menu").hide();
  465.  
  466. if (localStorage.filter == "all_comments") {
  467. $("dd[id^=comment]").each(function() {
  468. $(this).prev().show();
  469. $(this).show();
  470. });
  471. } else if (localStorage.filter == "only_reply_and_links") {
  472. $("dd[id^=comment]").each(function() {
  473. if ($(this).find("a, img").length === 0) {
  474. $(this).prev().hide();
  475. $(this).hide();
  476. } else {
  477. $(this).prev().show();
  478. $(this).show();
  479. }
  480. });
  481. } else if (localStorage.filter == "only_links_and_images") {
  482. $("dd[id^=comment]").each(function(index) {
  483. if ($(this).find("a[href^='http:'], img").length === 0 && index !== 0) {
  484. $(this).prev().hide();
  485. $(this).hide();
  486. } else {
  487. $(this).prev().show();
  488. $(this).show();
  489. }
  490. });
  491.  
  492. } else if (localStorage.filter == "only_images") {
  493. $("dd[id^=comment]").each(function() {
  494. if ($(this).find("img").length === 0) {
  495. $(this).prev().hide();
  496. $(this).hide();
  497. } else {
  498. $(this).prev().show();
  499. $(this).show();
  500. }
  501. });
  502. }
  503.  
  504. }
  505.  
  506. function pc_filter_comments() {
  507. if (this.nodeName !== undefined && this.id !== undefined)
  508. localStorage.filter = this.id;
  509.  
  510. $("ul.filter-menu>li").each(function() {
  511. if (this.id == localStorage.filter)
  512. this.css("background", "#d8edff");
  513. else
  514. this.css("background", "#fff");
  515. });
  516. $("ul.filter-menu").hide();
  517.  
  518. if (localStorage.filter == "all_comments") {
  519. $("dd[id^=comment]").each(function() {
  520. $(this).prev().show();
  521. $(this).show();
  522. });
  523. } else if (localStorage.filter == "only_reply_and_links") {
  524. $("dd[id^=comment]").each(function() {
  525. if ($(this).find("a, img").length === 0) {
  526. $(this).prev().hide();
  527. $(this).hide();
  528. } else {
  529. $(this).prev().show();
  530. $(this).show();
  531. }
  532. });
  533. } else if (localStorage.filter == "only_links_and_images") {
  534. $("dd[id^=comment]").each(function() {
  535. if ($(this).find("a[href^='http:'], img").length === 0) {
  536. $(this).prev().hide();
  537. $(this).hide();
  538. } else {
  539. $(this).prev().show();
  540. $(this).show();
  541. }
  542. });
  543.  
  544. } else if (localStorage.filter == "only_images") {
  545. $("dd[id^=comment]").each(function() {
  546. if ($(this).find("img").length === 0) {
  547. $(this).prev().hide();
  548. $(this).hide();
  549. } else {
  550. $(this).prev().show();
  551. $(this).show();
  552. }
  553. });
  554. }
  555.  
  556. }
  557.  
  558. if (location.href.match("https://www.logsoku.com/search")) {
  559. var results = document.getElementById("search_result_threads");
  560. if (results) {
  561. var titles = results.getElementsByClassName("title");
  562.  
  563. for (i = 0; i < titles.length; i++) {
  564. var link = titles[i].children[0];
  565. if (link)
  566. link.href = link.href + "l" + search_result_latest_floors;
  567. }
  568. }
  569. }
  570.  
  571.  
  572. if (location.href.match("https://www.logsoku.com/r/")) {
  573. $("div.comment").each(function() {
  574. if ($(this).find("a[href^='http://l.moapi.net/'], img").length === 0)
  575. $(this).parent().hide();
  576. else
  577. $(this).parent().show();
  578. });
  579.  
  580. var links = document.links;
  581. for (j = 0; j < links.length; j++) {
  582. links[j].href = links[j].href.replace("http://l.moapi.net/", "");
  583.  
  584. if (links[j].innerHTML.match(/.\.(jpg|jpeg|gif|png|JPG|JPEG|GIF|PNG)(:orig)?$/)) {
  585. var img = document.createElement("img");
  586. if (links[j].innerHTML.match(/\w*:?\/\//))
  587. img.src = links[j].innerHTML.replace(/\w*:?\/\//, "http://");
  588. else
  589. img.src = "http://" + links[j].innerHTML;
  590.  
  591. img.style.display = "none";
  592. img.onload = resize;
  593. if (click_to_hide_image)
  594. img.onclick = function() {
  595. this.style.display = "none";
  596. };
  597. if (popup_enable) {
  598. var container = document.createElement("div");
  599. container.style.display = "inline";
  600. container.onmouseover = function() {
  601. this.children[0].style.display = "inline";
  602. };
  603. container.onmouseout = function() {
  604. this.children[0].style.display = "none";
  605. };
  606. container.appendChild(img);
  607. }
  608. links[j].parentNode.replaceChild(container, links[j]);
  609. j--;
  610. }
  611.  
  612. }
  613. //pc_filter_comments();
  614.  
  615.  
  616. // var filter_menu = $("<li>", {class:"dropdown open filter"});
  617. // var innerHTML = "<a href='#' class='dropdown-toggle'>过滤<b class='caret'></b></a>";
  618. // innerHTML += "<ul class='dropdown-menu filter-menu' style='display:none'>";
  619. // innerHTML += "<li id='all_comments'><a>全部</a></li><li class='divider'></li>";
  620. // innerHTML += "<li id='all_comments_hide_images'><a>不显示图片</a></li><li class='divider'></li>";
  621. // innerHTML += "<li id='only_reply_and_links'><a>只含回复及链接</a></li><li class='divider'></li>";
  622. // innerHTML += "<li id='only_links_and_images'><a>只含链接及图片</a></li><li class='divider'></li>";
  623. // innerHTML += "<li id='only_images'><a>只含图片</a></li> </ul>";
  624. // filter_menu.html(innerHTML);
  625. // filter_menu.insertBefore($("ul.nav>li:last-child"));
  626. // var filter_clicked = function (filter) {
  627. // localStorage.filter = filter;
  628. // filter_comments();
  629. // }
  630. //
  631. // $("li.filter>a").click(function() {
  632. // $(this).next().toggle();
  633. // });
  634. //
  635. //
  636. // $("ul.filter-menu").on("click", "li", filter_comments);
  637.  
  638. $(".thread-nav>div").append($("<div>", {
  639. class: "icheckbox_line-grey",
  640. text: "只打开图片",
  641. click: openImages,
  642. style: "width:120px"
  643. }));
  644. var nav = document.getElementsByClassName("thread-nav")[0].children[0];
  645. if (nav) {
  646. var base = nav.children[2].href;
  647. nav.children[3].href = base + "l" + latest_floors;
  648.  
  649. for (i = 0; i < 1000 / contain_floores; i++) {
  650. var link = document.createElement("a");
  651. var range = String(i * contain_floores + 1) + "-" + String((i + 1) * contain_floores);
  652. link.href = base + range;
  653. link.innerHTML = range;
  654. link.className = "nav-btn";
  655. nav.appendChild(link);
  656. }
  657. }
  658.  
  659.  
  660.  
  661.  
  662. var hide_name = true;
  663. if (hide_name) {
  664. var names = document.querySelectorAll("span.nem, span.em");
  665. for (i = 0; i < names.length; i++) {
  666. names[i].style.display = "none";
  667. names[i].nextSibling.replaceData(0, 3, "");
  668. colon_pos = names[i].previousSibling.text.indexOf(":");
  669. names[i].previousSibling.replaceData(colon_pos + 1, 1, "");
  670. }
  671. }
  672.  
  673. var comments = document.getElementsByClassName("comment");
  674. for (i = 0; i < comments.length; i++) {
  675. var id = comments[i].previousSibling.previousSibling.text;
  676. if (localStorage.blacklist_ids.indexOf(id) >= 0) {
  677. comments[i].parentNode.style.display = "none";
  678. }
  679. console.log(localStorage.blacklist_ids);
  680.  
  681.  
  682. var hide_id = document.createElement("span");
  683. hide_id.innerHTML = "&nbsp;(block this ID'comemnts)";
  684. hide_id.style.color = "#666";
  685. hide_id.style.cursor = "pointer";
  686. hide_id.onclick = function() {
  687. localStorage.blacklist_ids += id + " ";
  688. this.parentNode.style.display = "none";
  689. };
  690. comments[i].parentNode.insertBefore(hide_id, comments[i]);
  691. }
  692.  
  693.  
  694. var search_box = document.getElementsByClassName("top-search-box").parentNode;
  695. var black_list = document.createElement("li");
  696. var black_list_link = document.createElement("a");
  697. black_list_link.onclick = function() {
  698. this.previousSibling.style.display = "inline";
  699. };
  700. var black_list_text = document.createElement("span");
  701. black_list_text.innerHTML = "black list";
  702. black_list_link.appendChild(black_list_text);
  703. search_box.appendChild(black_list_link);
  704.  
  705.  
  706. // draw black list configuration board
  707. var black_list_configuration = document.createElement("div");
  708. black_list_configuration.style.textAlign = "center";
  709. var close = document.createElement("a");
  710. close.innerHTML = "&#10006;&times;";
  711. close.style.cssText = "float:right; padding:3px; border:1px #666 solid";
  712. close.onclick = function() {
  713. this.parentNode.style.display = "inline";
  714. };
  715. black_list_configuration.appendChild(close);
  716.  
  717. var text = document.createElement("span");
  718. text.innerHTML = "IDs in the black list(seperate by space):";
  719. black_list_configuration.appendChild(text);
  720. var textarea = document.createElement("textarea");
  721. textarea.innerHTML = localStorage.blacklist_ids;
  722. textarea.id = "blacklist_ids";
  723. black_list_configuration.appendChild(textarea);
  724.  
  725. var text = document.createElement("span");
  726. text.innerHTML = "Contents in the black list(seperate by new line):";
  727. black_list_configuration.appendChild(text);
  728. var textarea = document.createElement("textarea");
  729. textarea.innerHTML = localStorage.blacklist_contents;
  730. textarea.id = "blacklist_contents";
  731. black_list_configuration.appendChild(textarea);
  732.  
  733. var close = document.createElement("a");
  734. close.innerHTML = "save";
  735. close.style.cssText = "padding:3px; border:1px #666 solid";
  736. close.onclick = function() {
  737. var input = document.getElementById("blacklist_ids");
  738. localStorage.blacklist_ids = input.nodeValue;
  739. input = document.getElementById("blacklist_contents");
  740. localStorage.blacklist_contents = input.nodeValue;
  741. this.parentNode.style.display = "none";
  742. };
  743. black_list_configuration.appendChild(close);
  744.  
  745. }
  746.  
  747. function resize() {
  748. var w = this.naturalWidth;
  749. var h = this.naturalHeight;
  750. var width = this.naturalWidth * percent;
  751. var height = this.naturalHeight * percent;
  752.  
  753. height = height > image_max_height ? image_max_height : height;
  754. height = height < image_min_height ? image_min_height : height;
  755. width = height * w / h;
  756.  
  757.  
  758. width = width > image_max_width ? image_max_width : width;
  759. width = width < image_min_width ? image_min_width : width;
  760. height = width * h / w;
  761.  
  762. height = height > image_max_height ? image_max_height : height;
  763. height = height < image_min_height ? image_min_height : height;
  764. width = height * w / h;
  765.  
  766. this.width = width;
  767. this.height = height;
  768. this.style.display = "block";
  769.  
  770.  
  771. //insert popup image
  772. if (popup_enable) {
  773. var popup_img = document.createElement("img");
  774. width = w;
  775. height = h;
  776. var clientWidth = document.body.clientWidth;
  777. var clientHeight = document.body.clientHeight;
  778.  
  779.  
  780. if (height > clientHeight) {
  781. heigth = clientHeight;
  782. width = clientHeight * w / h;
  783. }
  784. if (width > clientWidth) {
  785. width = clientWidth;
  786. height = clientWidth * h / w;
  787.  
  788. if (height > clientHeight) {
  789. heigth = clientHeight;
  790. width = clientHeight * w / h;
  791. }
  792. }
  793. popup_img.heigth = height;
  794. popup_img.width = width;
  795.  
  796. popup_img.src = this.src;
  797. popup_img.style.zIndex = 2;
  798. popup_img.style.position = "fixed";
  799. popup_img.style.left = "0px";
  800. popup_img.style.top = "0px";
  801. popup_img.style.display = "none";
  802. //popup_img.onmouseout = function() { this.style.display = "none"};
  803. //var download = document.createElement("a");
  804. //download.setAttribute("download", "");
  805. //download.appendChild(popup_img);
  806. this.parentNode.insertBefore(popup_img, this);
  807. this.parentNode.heigth = height;
  808. this.parentNode.width = width;
  809. }
  810.  
  811. }
  812.  
  813.  
  814.  
  815. function openImages() {
  816. var images = "";
  817. for (var i = 0; i < $(".comment img").length; i++) {
  818. images += "<img style='width:inherit' src='" + $(".comment img")[i].src + "'><br>";
  819. }
  820. var images_window = window.open("", "images", "width=240, height=100");
  821. var message = "<div unselectable='on' style='user-select:none' selectstart='return false;'>Please press Ctrl+A.<br>Then Press Ctrl+C.<br>Because browser not allow script to copy images to clipboard. </div>";
  822. images_window.document.write(images);
  823. }
  824.  
  825. jQuery.fn.disableSelection = function() {
  826. return this.attr('unselectable', 'on').css('user-select', 'none').on('selectstart', false);
  827. };
  828.  
  829. //@ sourceURL=2ch.js