Forked from anevins12/gist:02728f7c256adae7baafc5ddb1b15982
Created
January 24, 2022 14:33
-
-
Save mmarj/8e01a3e6dd9cfe5ea246711d0c6e985b to your computer and use it in GitHub Desktop.
Revisions
-
anevins12 revised this gist
May 18, 2018 . 1 changed file with 61 additions and 20 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ // @grant none // ==/UserScript== (function(isPluginReview, checkData) { 'use strict'; var $ = jQuery, @@ -20,28 +20,54 @@ }, namespace, matchedStoredCollection, identifierClass = 'wp-duplicate-review-flag', message, messageClass = 'wp-duplicate-message', removeData = $('<button class="wp-remove-data">🚩 Clear duplicated reviews</button>'); if (isPluginReview($)) { reviewCollection.plugin = $('.bbp-breadcrumb-forum').text(); reviewCollection.ip = $('.bbp-topic-ip').text().replace(/["'()]/g, ''); reviewCollection.url = window.location.pathname; namespace = 'wp-reviewee-'; matchedStoredCollection = JSON.parse(localStorage.getItem(namespace + reviewCollection.ip)); removeData .css({ 'fontSize': '80%', 'position': 'relative', 'top': '-1em' }) .on('click', function() { var button = $(this), message = $('.' + identifierClass); checkData(namespace, true); button .css('border-color', 'lawngreen') .html('🚩 Duplicated reviews cleared') .delay(2000) .fadeOut(); if (message.length !== 0) { message.remove(); } }); // If reviews have been stored if (checkData(namespace)) { $('.bbp-breadcrumb').prepend(removeData); } if (matchedStoredCollection) { message = $('<a class="' + messageClass + ' author-badge author-badge-plugin' + identifierClass + '" href="' + matchedStoredCollection.url + '">Duplicate review</a>'); // If this is a new review but for the same plugin & IP if (matchedStoredCollection.plugin === reviewCollection.plugin && matchedStoredCollection.ip === reviewCollection.ip && matchedStoredCollection.url !== reviewCollection.url) { message.css({ 'background': 'red', 'color': 'white', 'fontWeight': '700', @@ -51,20 +77,14 @@ 'textDecoration': 'underline' }); $('.bbp-topic-ip').append(message); } } else { localStorage.setItem(namespace + reviewCollection.ip, JSON.stringify(reviewCollection)); } } })(isPluginReview, checkData); function isPluginReview($) { 'use strict'; @@ -78,14 +98,35 @@ function isPluginReview($) { return false; } function checkData(name, destroy) { /* * Returns truthy if is data stored * Destroys data if argument passed */ 'use strict'; var reviewData = [], check = function(key) { if (/^/ + name) { reviewData.push(key); if (destroy) { localStorage.removeItem(key); } } }; Object .keys(localStorage) .forEach(function(key) { check(key); }); if (reviewData.length > 1) { return true; } else { return false; } } -
anevins12 revised this gist
May 18, 2018 . 1 changed file with 43 additions and 15 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -8,7 +8,7 @@ // @grant none // ==/UserScript== (function(isPluginReview, clearData) { 'use strict'; var $ = jQuery, @@ -18,37 +18,53 @@ ip: 0, url: '' }, namespace, matchedStoredCollection, identifier, removeData = $('<button class="wp-remove-data">🚩 Clear duplicated reviews</button>'); removeData.css({ 'border': '1px solid red' }); if (isPluginReview($)) { reviewCollection.plugin = $('.bbp-breadcrumb-forum').text(); reviewCollection.ip = $('.bbp-topic-ip').text().replace(/["'()]/g, ''); reviewCollection.url = window.location.pathname; namespace = 'wp-reviewee-'; matchedStoredCollection = JSON.parse(localStorage.getItem(namespace + reviewCollection.ip)); if (matchedStoredCollection) { identifier = $('<a class="bbp-topic-ip-info author-badge " href="' + matchedStoredCollection.url + '">Duplicate review</a>'); // If this is a new review but for the same plugin & IP if (matchedStoredCollection.plugin === reviewCollection.plugin && matchedStoredCollection.ip === reviewCollection.ip && matchedStoredCollection.url !== reviewCollection.url) { identifier.css({ 'background': 'red', 'color': 'white', 'fontWeight': '700', 'fontSize': '150%', 'margin-top': '-5px', 'margin-left': '-1em', 'textDecoration': 'underline' }); $('.bbp-topic-ip').append(identifier); } } else { localStorage.setItem(namespace + reviewCollection.ip, JSON.stringify(reviewCollection)); } } removeData.on('click', function() { clearData($, namespace); }); $('.bbp-breadcrumb').prepend(removeData); })(isPluginReview, clearData); function isPluginReview($) { 'use strict'; @@ -60,4 +76,16 @@ function isPluginReview($) { } return false; } function clearData($, name) { 'use strict'; Object .keys(localStorage) .forEach(function(key) { if (/^/ + name) { localStorage.removeItem(key); } }); } -
anevins12 created this gist
May 18, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,63 @@ // ==UserScript== // @name Dupe review helper // @namespace http://tampermonkey.net/ // @version 0.1 // @description Watches out for reviews made by the same IP subnet // @author anevins12 // @match https://wordpress.org/support/topic/* // @grant none // ==/UserScript== (function(isPluginReview) { 'use strict'; var $ = jQuery, pluginName, reviewCollection = { plugin: '', ip: 0, url: '' }, flag, matchedStoredCollection; if (isPluginReview($)) { reviewCollection.plugin = $('.bbp-breadcrumb-forum').text(); reviewCollection.ip = $('.bbp-topic-ip').text().replace(/["'()]/g, ''); reviewCollection.url = window.location.pathname; flag = 'wp-reviewee-'; matchedStoredCollection = JSON.parse(localStorage.getItem(flag + reviewCollection.ip)); if (matchedStoredCollection) { // If this is a new review but for the same plugin & IP if (matchedStoredCollection.plugin === reviewCollection.plugin && matchedStoredCollection.ip === reviewCollection.ip && matchedStoredCollection.url !== reviewCollection.url) { $('.bbp-topic-ip') .append('<a class="bbp-topic-ip-info" href="' + matchedStoredCollection.url + '">Dupe</a>') .css({ 'color': 'red', 'fontWeight': '700', 'fontSize': '150%' }); } } else { localStorage.setItem(flag + reviewCollection.ip, JSON.stringify(reviewCollection)); } } })(isPluginReview); function isPluginReview($) { 'use strict'; var ratings = $('.single-topic .wporg-ratings'); if (ratings.length !== 0) { return true; } return false; }