Advertisement
Guest User

linux.org.ru cut/code hider

a guest
Dec 19th, 2014
495
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        LOR spoiler
  3. // @namespace   linux.org.ru
  4. // @description Add spoiler functionality
  5. // @include     https://linux.org.ru/*
  6. // @include     https://www.linux.org.ru/*
  7. // @version     1
  8. // @grant       none
  9. // ==/UserScript==
  10.  
  11. $script.ready('jquery',function(){
  12.   console.log('LOR spoiler is ON');
  13.  
  14.   // spoiler
  15.   var cuts = $('[id ^= cut]');
  16.   cuts.each(function(){
  17.    
  18.     if($(this).text().split("\n").length<=5) return; // allow small cut
  19.    
  20.     var cut_id = $(this).attr('id');
  21.     $(this).hide();
  22.     $(this)
  23.       .before(
  24.         '<span class="sign">'+
  25.           '<span>&gt;&gt;&gt;&nbsp;</span>'+
  26.           '<a '+
  27.           'id="spoiler-'+ cut_id +'" '+
  28.           'href="javascript:void(0);" '+
  29.           'onClick="javascript:$(\'#'+ cut_id +'\').css(\'display\')==\'none\'?$(\'#'+ cut_id +'\').show():$(\'#'+ cut_id +'\').hide();">'+
  30.           'cut-spoiler'+
  31.           '</a>'+
  32.         '</span>'
  33.       );
  34.   });
  35.  
  36.   // code
  37.   var code_id = 0;
  38.   $('.code').each(function(){
  39.    
  40.     var no_hl = $(this).find('pre.no-highlight code');
  41.     if(no_hl.length>0){
  42.       if(no_hl.text().split("\n").length<=5) return; // allow small cut
  43.     } else {
  44.       if($(this).text().split("\n").length<=5) return; // allow small cut
  45.     }
  46.    
  47.     $(this).attr('id','hide-code'+ code_id).hide();
  48.     $(this)
  49.       .before(
  50.         '<span class="sign">'+
  51.         '<span>&gt;&gt;&gt;&nbsp;</span>'+
  52.         '<a '+
  53.           'id="spoiler-hide-code'+ code_id +'" '+
  54.           'href="javascript:void(0);" '+
  55.           'onClick="javascript:$(\'#hide-code'+ code_id +'\').css(\'display\')==\'none\'?$(\'#hide-code'+ code_id +'\').show():$(\'#hide-code'+ code_id +'\').hide();">'+
  56.           'code-spoiler'+
  57.           '</a>'+
  58.         '</span>'
  59.       );
  60.     code_id+=1;
  61.   });
  62. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement