SHARE
TWEET

Habbabreak2 v1.2

a guest Apr 20th, 2016 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name        Habbabreak2
  3. // @namespace   http://habbabreak2.nil
  4. // @description Sanity helper script for Craig Murray's blog
  5. // @include     https://www.craigmurray.org.uk/*
  6. // @version     1.2
  7. // @grant       GM_getValue
  8. // @grant       GM_setValue
  9. // @grant       GM_deleteValue
  10. // @require     http://code.jquery.com/jquery-1.7.2.min.js
  11. // @license     Unlicense
  12. // ==/UserScript==
  13.  
  14. var styles = '<style>' +
  15.     'div#habbabreak_options_div {display:none; background-color:#fff; padding:5px; border:1px #ccc solid;}' +
  16.     'input#habbabreak_add_person_input {max-width:300px;}' +
  17.     'a#habbabreak_disable_a.disabled {color:red;} div#habbabreak_options_div a {color:#262626; background: #ffff66;}' +
  18.     'a#habbabreak_toggle_options_a.disabled, a#habbabreak_toggle_options_a:visited.disabled {color:red;}' +
  19.     'a#habbabreak_toggle_options_a.disabled:hover {color:#28B7FF;} ' +
  20.     '</style>';
  21. var boldstyle = '<style>' +
  22.     'article p>a, article p>a:hover {color:#262626; background: #ffff66;} article p {color:#262626; font-size:17px; line-height: 24px;} aside#text-10, aside#text-12, aside#archives-5, aside#categories-5{display:none;}' +
  23.     'aside a {color:#a27210;}' +
  24.     '</style>';
  25. var peopletohide = function(s) {
  26.     var pth = [];
  27.     var pstr = GM_getValue('var-people-to-hide');
  28.     if (pstr) {
  29.        pth = pstr.split(s);
  30.        pth.splice(-1,1); // remove last empty string from array
  31.     }
  32.     return pth;
  33. };
  34. jQuery.expr[':'].icontains = function(a, i, m) {
  35.     return jQuery(a) .text() .toUpperCase() .indexOf(m[3] .toUpperCase()) >= 0;
  36. };
  37. $(document) .ready(function () {
  38.     $('head') .append(styles);
  39.     if (GM_getValue('var-option-bold')) $('head') .append(boldstyle);
  40.     $('#menu-main-2') .append('<li><a href="" id="habbabreak_toggle_options_a">Habbabreak</a></li>');
  41.     if (GM_getValue('var-script-disabled')) $('a#habbabreak_toggle_options_a') .addClass('disabled');  
  42.     var splitstring = "/c*nt^"; // DO NOT CHANGE
  43.     // Options form html
  44.     var options = '<div id="habbabreak_options_div">' +
  45.        '<h3>Habbabreak V2</h3><div id="habbabreak_people_to_hide_div"></div>' +
  46.        '<p><input type="input" id="habbabreak_add_person_input" placeholder="Loose matching eg habba will hide Habbakuk" maxlength="20"/> <a href="" id="habbabreak_add_person_a">add person</a></p>' +
  47.        '<p><label><input type="checkbox" id="habbabreak_bold"/> High contrast</label></p>' +
  48.        '<div><a href="" id="habbabreak_save_options_a">Save</a> | <a href="" id="habbabreak_cancel_options_a">Close</a> | <a href="" id="habbabreak_disable_a">Disable</a></div>' +
  49.        '</div>' ;
  50.     // Add divs to page
  51.     $('#main-wrapper') .prepend(options);
  52.     // Show/hide options form
  53.     $('a#habbabreak_toggle_options_a') .click(function () {
  54.        if (!$('#habbabreak_options_div') .is(":visible")) {
  55.           $('#habbabreak_people_to_hide_div') .empty();
  56.           // Display saved option values
  57.           peopletohide(splitstring).forEach(function(value) {
  58.              if (value.length > 0) {
  59.                 $('#habbabreak_people_to_hide_div') .append('<p><span>' + value + '</span> <a href="" class="remove_user">remove</a></p>');    
  60.              }
  61.           });  
  62.           if (GM_getValue('var-option-bold')) $('#habbabreak_bold') .attr('checked', 'checked');
  63.           if (GM_getValue('var-script-disabled')) {
  64.              $('#habbabreak_disable_a') .text('Enable');
  65.              $('a#habbabreak_disable_a') .addClass('disabled');          
  66.           }
  67.           $('#habbabreak_options_div') .show();
  68.           $('#habbabreak_add_person_input') .focus();
  69.        } else {
  70.           $('#habbabreak_options_div') .hide();
  71.        }
  72.        
  73.        return false;
  74.     });
  75.     // Disable/enable script link click
  76.     $('a#habbabreak_disable_a') .click(function () {
  77.         GM_setValue('var-script-disabled', !GM_getValue('var-script-disabled'));
  78.         $('#habbabreak_options_div') .hide();
  79.         return true;
  80.     });
  81.     // Add user link click
  82.     $('#habbabreak_options_div a#habbabreak_add_person_a') .click(function () {
  83.         var value = $('#habbabreak_add_person_input') .val() .trim();
  84.         if (value.length > 0) {
  85.             $('#habbabreak_people_to_hide_div') .append('<p><span>' + value + '</span> <a href="" class="remove_user">remove</a></p>');
  86.             $('#habbabreak_add_person_input') .val('');
  87.         } else {
  88.             alert ("Habbabreak V2:\nPlease enter a name!");
  89.             $('#habbabreak_add_person_input').focus();
  90.         }
  91.         return false;
  92.     });
  93.     // Remove user link click
  94.     $('#habbabreak_people_to_hide_div') .on('click', '.remove_user', function () {
  95.         $(this) .parents('p') .remove();
  96.         return false;
  97.     });
  98.     // Close form link click
  99.     $('a#habbabreak_cancel_options_a') .click(function () {
  100.         $('#habbabreak_options_div') .hide();
  101.         return false;
  102.     });
  103.     // Save options link click
  104.     $('a#habbabreak_save_options_a') .click(function () {
  105.         // Delete existing saved options
  106.         GM_deleteValue('var-people-to-hide');
  107.         GM_deleteValue('var-script-disabled');
  108.         GM_deleteValue('var-option-bold');        
  109.         // Save new options
  110.         var pthstr = '';
  111.         $('#habbabreak_people_to_hide_div p span') .each(function () {
  112.             pthstr += $(this) .text() + splitstring;
  113.         });
  114.         if( pthstr.length > 0 ) GM_setValue('var-people-to-hide', pthstr);
  115.         GM_setValue('var-option-bold', $('#habbabreak_bold') .attr('checked') == 'checked');
  116.         // Hide options window
  117.         $('#habbabreak_options_div') .hide();
  118.         // Force page reload
  119.         return true;
  120.     });
  121.     var url = window.location.href;
  122.     var isforum = false;
  123.     if (url.lastIndexOf('craigmurray.org.uk/forums') > -1) isforum = true;
  124.     // Hide comments, forum posts & aside links to these
  125.     if (!GM_getValue('var-script-disabled')) {
  126.        peopletohide(splitstring) .forEach(function(value) {
  127.           if (isforum) {
  128.               var forumposts = $('div.bbp-reply-author') .filter(function () {
  129.                  return $(this) .is(':icontains(' + value + ')');
  130.               }) .parents('li') ;
  131.               forumposts .hide();
  132.           } else {
  133.               var comments = $('header.comment-author') .filter(function () {
  134.                  return $(this) .is(':icontains(' + value + ')');
  135.               }) .parents('article') ;
  136.               comments .hide();
  137.           }
  138.           var recentcomments = $('span.comment-author-link') .filter(function () {
  139.              return $(this) .is(':icontains(' + value + ')');
  140.           }) .parents('li') ;
  141.           recentcomments .hide();
  142.           var recentreplies = $('aside#bbp_replies_widget-2') .children('ul') .children('li') .filter(function () {
  143.              return $(this) .is(':icontains(' + value + ')');
  144.           }) ;
  145.           recentreplies .hide();
  146.        });
  147.     };
  148.     // Show comment/post if in URL
  149.     var pos;
  150.     if (isforum)
  151.         pos = url.lastIndexOf('#post-');
  152.     else
  153.        pos = url.lastIndexOf('#comment-');
  154.     if (pos > -1) {
  155.         var divid = url.substring(pos, url.length);
  156.         $('html, body') .scrollTop($(divid).offset().top);
  157.     }
  158. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top