Advertisement
tonyrulez

PH! forum SPOILER elrejto v0.4.1 [UserScript]

Nov 9th, 2014
219
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        PH! forum SPOILER elrejto
  3. // @author      http://prohardver.hu/tag/spammer.html
  4. // @namespace   https://greasyfork.org/users/2358-spammer
  5. // @version     0.4.1
  6. // @description A PH! lapcsalad forumaban a spoiler tagekkel ellatott szovegreszeket rejti el.
  7. // @match       http://prohardver.hu/tema/*
  8. // @match       http://itcafe.hu/tema/*
  9. // @match       http://gamepod.hu/tema/*
  10. // @match       http://mobilarena.hu/tema/*
  11. // @match       http://logout.hu/tema/*
  12.  
  13. // @match       http://m.prohardver.hu/tema/*
  14. // @match       http://m.itcafe.hu/tema/*
  15. // @match       http://m.gamepod.hu/tema/*
  16. // @match       http://m.mobilarena.hu/tema/*
  17. // @match       http://m.logout.hu/tema/*
  18.  
  19. // @match       http://prohardver.hu/muvelet/hsz/*
  20. // @match       http://itcafe.hu/muvelet/hsz/*
  21. // @match       http://gamepod.hu/muvelet/hsz/*
  22. // @match       http://mobilarena.hu/muvelet/hsz/*
  23. // @match       http://logout.hu/muvelet/hsz/*
  24. // @match       http://logout.hu/bejegyzes/*
  25. // @require     http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  26. // @grant       none
  27. // ==/UserScript==
  28.  
  29.  
  30. $(document).ready(function () {
  31.            
  32.     //---------------------------------//
  33.     //----- 1. Var --------------------//
  34.     //---------------------------------//    
  35.    
  36.     var $OPENING_TAG = '[SPOILER]';
  37.     var $CLOSING_TAG = '[/SPOILER]';    
  38.     var $SPOILER_WARNING = 'SPOILER! megtekintése';
  39.     var $spoiler_wrap = '<div class="spoiler_wrap"></div>';
  40.     var check_domain = window.location.hostname; //mobilos nezethez (m-es domain)
  41.    
  42.        
  43.     //mobilos nezethez mas style-t kell be betolteni, ezert csekkoljuk, hogy m-es domain cím-e
  44.     if(check_domain === "m.prohardver.hu" || check_domain === "m.itcafe.hu" || check_domain === "m.gamepod.hu" || check_domain === "m.mobilarena.hu" || check_domain === "m.logout.hu") {
  45.         console.log('mobile vars loaded: '+check_domain);
  46.      
  47.         var $spoiler_alert_CSS  = {
  48.          
  49.             "padding":"5px",
  50.             "margin-top":"15px",
  51.             "box-sizing":"border-box",
  52.             "color":"#c90000",
  53.             "font-weight":"bold",
  54.             "font-size":"11px",
  55.             "cursor":"pointer"
  56.         }
  57.        
  58.         var $spoiler_wrap_CSS  = {
  59.        
  60.         "box-sizing":"border-box",
  61.         "padding":"5px 0 10px 5px"
  62.        
  63.         }
  64.        
  65.     } else {
  66.         console.log('desktop vars loaded: '+check_domain);
  67.    
  68.         var $spoiler_alert_CSS  = {
  69.            
  70.             "background": "rgba(0,0,0,0.05)",
  71.             "border":"1px dashed rgba(0,0,0,0.25)",
  72.             "border-radius":"3px",
  73.             "padding":"5px",
  74.             "margin-top":"15px",
  75.             "box-sizing":"border-box",
  76.             "color":"#c90000",
  77.             "font-weight":"bold",
  78.             "font-size":"11px",
  79.             "cursor":"pointer"
  80.        
  81.         }
  82.        
  83.         var $spoiler_wrap_CSS  = {
  84.        
  85.         "background": "rgba(0,0,0,0.05)",
  86.         "border-left":"1px dashed rgba(0,0,0,0.25)",
  87.         "border-right":"1px dashed rgba(0,0,0,0.25)",
  88.         "border-bottom":"1px dashed rgba(0,0,0,0.25)",
  89.         "border-radius":"3px",
  90.         "box-sizing":"border-box",
  91.         "padding":"5px 0 10px 5px"
  92.        
  93.         }
  94.        
  95.     } //if -> else vege
  96.    
  97.  
  98.     var $SPOILER_OPEN_ONLY = $('.text p').filter(function() { return $(this).text() ===  $OPENING_TAG;});
  99.     var $SPOILER_CLOSE_ONLY = $('.text p').filter(function() { return $(this).text() ===  $CLOSING_TAG;});
  100.     var $SPOILER_BLOCK = $('.text p:contains('+$OPENING_TAG+'):contains('+$CLOSING_TAG+')');
  101.     var $SPOILER_OPEN_TEXT = $('.text p:contains('+$OPENING_TAG+'):not(:contains('+$CLOSING_TAG+'))');
  102.     var $SPOILER_CLOSE_TEXT = $('.text p:contains('+$CLOSING_TAG+'):not(:contains('+$OPENING_TAG+'))');
  103.    
  104.     //--------------------------------------------------//
  105.     //------ 2. Classok hozzaadasa  --------------------//
  106.     //--------------------------------------------------//  
  107.    
  108.     $($SPOILER_OPEN_ONLY).each(function () { $(this).addClass("spoiler_open_only");  });
  109.     $($SPOILER_CLOSE_ONLY).each(function () { $(this).addClass("spoiler_close_only"); });
  110.     $($SPOILER_BLOCK).each(function () { $(this).addClass("spoiler_block"); });
  111.     $($SPOILER_OPEN_TEXT).each(function () { if ($(this).text().length > 9) { $(this).addClass("spoiler_open_text"); } });
  112.     $($SPOILER_CLOSE_TEXT).each(function () { if ($(this).text().length > 10) { $(this).addClass("spoiler_close_text"); } });
  113.    
  114.     //--------------------------------------------------//
  115.     //------ 3. Elemek szetbontasa es osszerakasa ------//
  116.     //--------------------------------------------------//  
  117.    
  118.     // --- 3.1. A nyito tag egy <p> blokkban van a szovegel
  119.     $('.spoiler_open_text').before('<p class="spoiler_open_only">'+$OPENING_TAG+'</p>'); //beszurunk egy uj onallo nyito tag blokkot
  120.     $('.spoiler_open_text:contains('+$OPENING_TAG+')').html(function() { return $(this).html().replace($OPENING_TAG, ''); }); //toroljuk a szovegbol a nyito taget
  121.     $('.spoiler_open_text').html(function() { return $(this).html().replace('<br>', ''); }); //toroljuk a sortorest, ami a nyito tag utan volt, hogy ne legyen hezag a szoveg elott.
  122.    
  123.     // --- 3.2. A zaro tag egy <p> blokkban van a szovegel
  124.     $('.spoiler_close_text').after('<p class="spoiler_close_only">'+$CLOSING_TAG+'</p>'); //beszurunk egy uj onallo zaro tag blokkot
  125.     $('.spoiler_close_text:contains('+$CLOSING_TAG+')').html(function() { return $(this).html().replace($CLOSING_TAG, ''); }); //toroljuk a szovegbol a zaro taget
  126.    
  127.     // --- 3.3. A nyito es a zaro tag is egy <p> blokkban van a szoveggel
  128.     $('.spoiler_block').before('<p class="spoiler_open_only">'+$OPENING_TAG+'</p>'); //beszurunk egy uj onallo nyito tag blokkot
  129.     $('.spoiler_block').after('<p class="spoiler_close_only">'+$CLOSING_TAG+'</p>'); //beszurunk egy uj onallo zaro tag blokkot
  130.     $('.spoiler_block:contains('+$OPENING_TAG+')').html(function() { return $(this).html().replace($OPENING_TAG, ''); }); //toroljuk a szovegbol a nyito taget
  131.     $('.spoiler_block:contains('+$CLOSING_TAG+')').html(function() { return $(this).html().replace($CLOSING_TAG, ''); }); //toroljuk a szovegbol a zaro taget
  132.     $('.spoiler_block').html(function() { return $(this).html().replace('<br>', ''); }); //toroljuk a sortorest, ami a nyito tag utan volt, hogy ne legyen hezag a szoveg elott.
  133.  
  134.    
  135.     //-------------------------------------------------------------//
  136.     //------ 4. Spoiler elrejtese, csomagolasa, megjelenitese -----//
  137.     //-------------------------------------------------------------//
  138.    
  139.     //mobilos nezethez mas style-t kell be betolteni, ezert csekkoljuk, hogy m-es domain cím-e
  140.     if(check_domain === "m.prohardver.hu" || check_domain === "m.itcafe.hu" || check_domain === "m.gamepod.hu" || check_domain === "m.mobilarena.hu" || check_domain === "m.logout.hu") {
  141.        
  142.         var $spoiler_wrap_p_style = 'margin-top:5px!important';
  143.         console.log('mobile .spoiler_wrap p style loaded: '+check_domain);
  144.    
  145.     } else {
  146.        
  147.         var $spoiler_wrap_p_style = 'margin-top:5px!important;max-width:465px';
  148.         console.log('desktop .spoiler_wrap p style loaded: '+check_domain);
  149.     }
  150.    
  151.    
  152.     $('.spoiler_open_only').nextUntil($('.spoiler_close_only')).hide(); //elrejtunk mindent a 2 tag kozott
  153.     $('.spoiler_open_only').text($SPOILER_WARNING).css($spoiler_alert_CSS); //a nyito taget lecsereljuk formazott figyelmezteto szovegre
  154.    
  155.    
  156.     //A mar formazott figyelmezteto szovegre kattintva kinyitjuk vagy becsukjuk a spoileres tartalmat
  157.     $('.spoiler_open_only').click(function() {
  158.        
  159.         if ($(this).nextAll().css('display') == 'none') {
  160.            
  161.             $(this).nextUntil($('.spoiler_close_only')).wrapAll($spoiler_wrap); //spoileres tartalom becsomagolasa
  162.             $(".spoiler_wrap").css($spoiler_wrap_CSS); //alkalmazzuk a css-t a wrapperre
  163.             $(".spoiler_wrap p").attr('style',$spoiler_wrap_p_style); //css helyett attr, kulonben az oldal margin-top !importantjat nem irja felul
  164.             $(".spoiler_wrap p small").css('color', '#000'); //offtopic betuk szinezese feketere
  165.             $(".spoiler_wrap").show(); //spoileres doboz kinyitasa
  166.             $(this).nextUntil($('.spoiler_close_only')).hide().fadeIn("200"); //spoileres tartalom megjelenitese
  167.              
  168.         } else {
  169.              
  170.             $(this).nextUntil($('.spoiler_close_only')).contents().unwrap(); //tobbszoros becsukas/kinyitas utan ne legyen tobbszoros wrappolas
  171.             $(this).nextUntil($('.spoiler_close_only')).hide(); //spoileres tartalom elrejtese
  172.            
  173.         }
  174.        
  175.     });
  176.      
  177.    
  178.     $('.spoiler_close_only').hide(); //a zaro taget minden esetben elrejtjuk
  179.    
  180.  
  181. //script vege
  182. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement