Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Hide Selected Scribd Items
- // @namespace petergblake.gmail.com
- // @include https://www.scribd.com/search?*
- // @grant GM.getValue
- // @grant GM.setValue
- // ==/UserScript==
- // Based on "Hide Selected Craigslist Listings" by vertigoelectric
- ShowHideToggle = 1;
- var $;
- // Scribd already uses jQuery, so there is no need to add it again
- // As of 6/2/2020, the version used is 3.3.1
- GM_wait();
- // Check if jQuery's loaded
- function GM_wait() {
- if (typeof unsafeWindow.jQuery == 'undefined') {
- window.setTimeout(GM_wait, 100);
- } else {
- $ = unsafeWindow.jQuery.noConflict(true);
- letsJQuery();
- }
- }
- function letsJQuery() {
- //alert($); // check if the dollar (jquery) function works
- //alert($().jquery); // check jQuery version
- // Fetch blocklist and break it into individual IDs
- IDlistArray = String(GM.getValue("scribdIDlist")).split("|");
- IDlistCount = IDlistArray.length - 1;
- // Add page-wide controls
- $('span.results_count').append(' <span id="HiddenCount">[Total hidden across Scribd: '+IDlistCount+']</span>');
- $('span.results_count').append('<input type="button" id="UnhideButton" onclick="unhideAll();" value="Unhide All '+IDlistCount+'">');
- $('span.results_count').append('<input type="button" id="ShowHideButton" onclick="ShowHidden();" value="Show Hidden">');
- if (IDlistCount < 1) {
- $('#ShowHideButton').attr('disabled','true');
- $('#UnhideButton').attr('disabled','true');
- }
- // Add item-level hide/unhide controls
- $('div.controls').append('<div><input title="Hide" type="button" id="hide" onclick="hideListing(this);" value="X"</div>');
- $('div.controls').append('<div><input title="Unhide" type="button" id="unhide" onclick="unhideListing(this);" value="X" style="display:none"</div>');
- // Hide each ID on the blocklist
- for (x in IDlistArray)
- {
- if (IDlistArray[x])
- {
- someID = IDlistArray[x];
- $('a[id="'+someID+'"]').parent().parent().css('display','none');
- }
- }
- // Hide the item corresponding to a particular "Hide" button
- function hideListing(node) {
- setTimeout(function() {
- someID = buttonPressed.parent().parent().getElementsByTagName('a')[0].getAttribute('id');
- itemID = "|"+someID;
- if (!GM.getValue("scribdIDlist")) {
- IDlist = "";
- var checkID = "";
- GM.setValue("scribdIDlist", String(itemID));
- } else {
- IDlist = GM.getValue("scribdIDlist");
- var checkID = IDlist.indexOf(itemID);
- if (checkID == -1) {
- newIDlist = itemID + GM.getValue("scribdIDlist");
- GM.setValue("scribdIDlist", String(newIDlist));
- }
- }
- // Hide "Hide" button
- buttonPressed.css('display','none');
- // Show corresponding "Unhide" button
- buttonPressed.parent().getElementById('unhide')[0].css('display','initial');
- // Hide or fade out this item
- if (ShowHideToggle == 0) {
- $('a[id="'+someID+'"]').parent().parent().css('opacity','0.3');
- } else if (ShowHideToggle == 1) {
- $('a[id="'+someID+'"]').parent().parent().css('display','none');
- }
- // Update total hidden
- IDlistArray = String(GM_getValue("scribdIDlist")).split("|");
- IDlistCount = IDlistArray.length - 1;
- $('#HiddenCount').html('[Total hidden across Scribd: '+IDlistCount+']');
- // Update page-level controls
- $('#ShowHideButton').removeAttr('disabled');
- $('#UnhideButton').removeAttr('disabled');
- }, 0);
- };
- // Components.utils.exportFunction(hideListing, unsafeWindow, { defineAs: "hideListing" });
- // Unhide the item corresponding to a particular "Unhide" button
- unsafeWindow.unhideListing = function(node) {
- setTimeout(function() {
- someID = buttonPressed.parent().parent().getElementsByTagName('a')[0].getAttribute('id');
- remitemID = "|"+someID;
- IDlist = GM.getValue("scribdIDlist");
- var checkID = IDlist.indexOf(remitemID);
- if (checkID != -1) {
- newIDlist = IDlist.replace(remitemID,'');
- GM.setValue("scribdIDlist", String(newIDlist));
- }
- // Hide "Unhide" button
- buttonPressed.css('display','none');
- // Unhide corresponding "Hide" button
- buttonPressed.parent().getElementById('hide')[0].css('display','initial');
- // Un-fade this item
- $('a[id="'+someID+'"]').parent().parent().css('display','initial');
- $('a[id="'+someID+'"]').parent().parent().css('opacity','1');
- // Update page-level controls
- IDlistArray = String(GM.getValue("scribdIDlist")).split("|");
- IDlistCount = IDlistArray.length - 1;
- if (IDlistCount < 1) {
- $('#ShowHideButton').attr('disabled','true');
- $('#UnhideButton').attr('disabled','true');
- }
- // Update total hidden
- $('#HiddenCount').html('[Total hidden across Scribd: '+IDlistCount+']');
- }, 0);
- };
- // Unhide everything, which is the same as erasing the blocklist
- unsafeWindow.unhideAll = function() {
- setTimeout(function() {
- GM_deleteValue("scribdIDlist");
- location.reload();
- }, 0);
- };
- // Toggle hidden documents between visible but faded and completely hidden
- unsafeWindow.ShowHidden = function() {
- setTimeout(function() {
- IDlistArray = String(GM.getValue("scribdIDlist")).split("|");
- if (ShowHideToggle == 1) {
- for (x in IDlistArray)
- {
- if (IDlistArray[x])
- {
- $('a[id="'+IDlistArray[x]+'"]').parent().parent().css('display','initial');
- $('a[id="'+IDlistArray[x]+'"]').parent().parent().css('opacity','0.3');
- }
- }
- $('#ShowHideButton').attr('value','Hide Again');
- ShowHideToggle = 0;
- } else if (ShowHideToggle == 0) {
- for (x in IDlistArray)
- {
- if (IDlistArray[x])
- {
- $('a[id="'+IDlistArray[x]+'"]').parent().parent().css('display','none');
- }
- }
- $('#ShowHideButton').attr('value','Show Hidden');
- ShowHideToggle = 1;
- }
- }, 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment