⬆ Update for new layout

This commit is contained in:
Dan Jones 2018-09-18 09:08:43 -05:00
commit 95f1340722

View file

@ -4,59 +4,66 @@
// @description Allow removal of visited links on Amazon Giveaway Listing // @description Allow removal of visited links on Amazon Giveaway Listing
// @include https://smile.amazon.com/ga/giveaways* // @include https://smile.amazon.com/ga/giveaways*
// @include https://www.amazon.com/ga/giveaways* // @include https://www.amazon.com/ga/giveaways*
// @version 1.8.0 // @version 1.9.0
// @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js // @require https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js
// ==/UserScript== // ==/UserScript==
var checked = false; /* global jQuery */
var regex_hide;
var getSmallUrl = function(fullUrl) { (function ($) {
return fullUrl.split('?')[0]; 'use strict';
};
var hideOne = function(el) { var checked = false;
$(el).parents('.giveawayItemContainer').css('display', checked ? 'none' : 'block'); var regex_hide;
};
var hideVisited = function(evt) { var getSmallUrl = function(fullUrl) {
checked = $(this).prop('checked'); return fullUrl.split('?')[0];
var $links = $('#giveaway-grid a[href*="amazon.com/ga"]'); };
var hide = regex_hide ? new RegExp(regex_hide, 'i') : null; var hideOne = function(el) {
$(el).parents('.listing-item').css('display', checked ? 'none' : 'block');
};
$links.each(function() { var hideVisited = function(evt) {
var href = getSmallUrl($(this).attr('href')); checked = $(this).prop('checked');
if (localStorage.getItem(href)) { var $links = $('.listing-info-container a[href*="/ga"]');
var hide = regex_hide ? new RegExp(regex_hide, 'i') : null;
$links.each(function() {
var href = getSmallUrl($(this).attr('href'));
if (localStorage.getItem(href)) {
hideOne(this);
}
var title = $(this).find('.prize-title').text();
if (hide && title && hide.test(title)) {
hideOne(this);
}
});
};
$(document).ready(function() {
//$('head').append('<base target="_blank" />');
$('.listing-info-container').on('click', 'a[href*="/ga"]', function(evt) {
var href = getSmallUrl($(this).attr('href'));
localStorage[href] = "visited";
hideOne(this); hideOne(this);
} });
var title = $(this).find('.giveawayPrizeNameContainer').text(); regex_hide = localStorage.getItem('regex_hide') || '';
if (hide && title && hide.test(title)) {
hideOne(this);
}
});
};
$(document).ready(function() { $('#giveaway-numbers-container')
$('head').append('<base target="_blank" />'); .append('<label><input type="checkbox" id="hide_visited"/> Visited</label>')
.append(`<input id="hide_regex" value="${regex_hide}"/>`);
$('#giveaway-grid').on('click', 'a[href*="amazon.com/ga"]', function(evt) { $('#hide_visited').on('click', hideVisited);
$('#hide_regex').on('change', function() {
var href = getSmallUrl($(this).attr('href')); regex_hide = $(this).val();
localStorage[href] = "visited"; localStorage.regex_hide = regex_hide;
hideOne(this); });
}); });
regex_hide = localStorage.getItem('regex_hide') || ''; })(jQuery);
$('#giveaway-result-info-bar-content')
.append('<label><input type="checkbox" id="hide_visited"/> Visited</label>')
.append(`<input id="hide_regex" value="${regex_hide}"/>`);
$('#hide_visited').on('click', hideVisited);
$('#hide_regex').on('change', function() {
regex_hide = $(this).val();
localStorage.regex_hide = regex_hide;
});
});