From b693d90e33cb51351934d5b0aad7d89603535bdc Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 2 Dec 2016 10:41:02 -0600 Subject: [PATCH] giveaway: use @require, and remove elements as you click --- giveaway.user.js | 44 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/giveaway.user.js b/giveaway.user.js index 0742c61..a07fba6 100644 --- a/giveaway.user.js +++ b/giveaway.user.js @@ -1,38 +1,38 @@ -// ==UserScript== +// ==UserScript== // @name Amazon Giveaway Listing Visited Remover // @namespace danielrayjones // @description Allow removal of visited links on Amazon Giveaway Listing // @include https://giveawaylisting.com/ -// @version 1.0 +// @version 1.3 +// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js // ==/UserScript== +var checked = false; + +var hideOne = function(el) { + $(el).parent('td').parent('tr').css('display', checked ? 'none' : 'table-row'); +}; + var hideVisited = function(evt) { - var checked = $jq(this).prop('checked'); - var $links = $jq('#giveaways a[href*="amzn.to"]'); + checked = $(this).prop('checked'); + var $links = $('#giveaways a[href*="amzn.to"]'); $links.each(function() { - var href = $jq(this).attr('href'); + var href = $(this).attr('href'); if (localStorage.getItem(href)) { - $jq(this).parent('td').parent('tr').css('display', checked ? 'none' : 'table-row'); + hideOne(this); } }); }; -var script = document.createElement("script"); -script.setAttribute("src", "//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"); -script.addEventListener('load', function() { +$(document).ready(function() { + $('#giveaways').on('click', 'a[href*="amzn.to"]', function(evt) { - window.$jq = jQuery.noConflict(); - $jq(document).ready(function() { - $jq('#giveaways').on('click', 'a[href*="amzn.to"]', function(evt) { - - var href = $(this).attr('href'); - localStorage[href] = "visited"; - - }); - - $jq('b:contains("Hide")').after(''); - $jq('#hide_visited').on('click', hideVisited); + var href = $(this).attr('href'); + localStorage[href] = "visited"; + hideOne(this); }); -}, false); -document.body.appendChild(script); + + $('b:contains("Hide")').after(''); + $('#hide_visited').on('click', hideVisited); +});