Guest User

Untitled

a guest
Sep 28th, 2013
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           DobroHider
  3. // @namespace      dobrocode
  4. // @description    Dobrochan threads autohider
  5. // @include        http://dobrochan.ru/*/*.xhtml
  6. // @include        https://dobrochan.ru/*/*.xhtml
  7. // @include        http://dobrochan.ru/settings
  8. // @include        https://dobrochan.ru/settings
  9. // @exclude        http://dobrochan.ru/*/res/*.xhtml*
  10. // @exclude        https://dobrochan.ru/*/res/*.xhtml*
  11. // @include        http://dobrochan.com/*/*.xhtml
  12. // @include        https://dobrochan.com/*/*.xhtml
  13. // @include        http://dobrochan.com/settings
  14. // @include        https://dobrochan.com/settings
  15. // @exclude        http://dobrochan.com/*/res/*.xhtml*
  16. // @exclude        https://dobrochan.com/*/res/*.xhtml*
  17.  
  18. // ==/UserScript==
  19. var script = document.createElement("script");
  20. script.textContent = "(" + main.toString() + ")();";
  21. document.body.appendChild(script);
  22.  
  23. function main() {
  24. function getCookie(name) {
  25.     var one, arr = document.cookie.split('; '), i = arr.length;
  26.     while(i--) { one = arr[i].split('='); if(one[0] == escape(name)) return unescape(one[1]); }
  27.     return false;
  28. }
  29.  
  30. function hide_thread_silent(board, thread)
  31. {
  32.     $.get('/api/thread/'+board+'/'+thread+'/hide.json', {}, function(response){$('#thread_'+thread).hide("slow")});
  33. }
  34.  
  35. // settings
  36. if(location.href=="https://dobrochan.ru/settings" || location.href=="http://dobrochan.ru/settings" || location.href=="https://dobrochan.com/settings" || location.href=="http://dobrochan.com/settings")
  37. {
  38. var global_table = document.getElementById('ajax-form').parentNode.parentNode
  39. var auto_column = document.createElement("td")
  40. var autohide_value = getCookie('autohide')
  41. auto_column.innerHTML = "<td><span class=\"logo\">Автоскрытие тредов:</span>" +
  42. "<br><textarea id=\"autohide_settings\" cols=\"60\" rows=\"10\" onChange=\"" +
  43. "document.cookie = escape('autohide') + '=' + escape(document.getElementById('autohide_settings').value) + ';expires=Mon, 01-Jan-2032 00:00:00 GMT'" +
  44. "\"></textarea></td>"
  45. auto_column.setAttribute("style","padding-left: 20px; vertical-align:top")
  46. global_table.appendChild(auto_column)
  47. if(autohide_value)
  48.     document.getElementById('autohide_settings').value = autohide_value
  49. }
  50. else
  51. {
  52. // board
  53. var auto_hide_arr = getCookie('autohide').split('\n')
  54. var op_posts = document.getElementsByClassName('oppost post')
  55. var desk = new RegExp("dobrochan.(?:ru|com)/([a-z]{1,4})").exec(location.href)[1];
  56. var index = 0;
  57. for( index = 0; index < op_posts.length; index++)
  58. {
  59.     var titles = op_posts[index].getElementsByClassName("replytitle");
  60.     if(titles.length > 0)
  61.     {
  62.         var op_title = titles[0].innerHTML
  63.         var rx_index = 0;
  64.         for( rx_index = 0; rx_index<auto_hide_arr.length; rx_index++)
  65.         {
  66.             if(auto_hide_arr[rx_index].length==0)
  67.                 continue
  68.             var rx = new RegExp(auto_hide_arr[rx_index],"i")
  69.             if(rx.test(op_title))
  70.             {
  71.                 var thread_id = op_posts[index].id;
  72.                 thread_id = thread_id.replace("post_","");
  73.                 hide_thread_silent(desk, thread_id)
  74.             }
  75.         }
  76.     }
  77. }
  78. }
  79. }
Advertisement
Add Comment
Please, Sign In to add comment