Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save mmarj/8e01a3e6dd9cfe5ea246711d0c6e985b to your computer and use it in GitHub Desktop.

Select an option

Save mmarj/8e01a3e6dd9cfe5ea246711d0c6e985b to your computer and use it in GitHub Desktop.

Revisions

  1. @anevins12 anevins12 revised this gist May 18, 2018. 1 changed file with 61 additions and 20 deletions.
    81 changes: 61 additions & 20 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    // @grant none
    // ==/UserScript==

    (function(isPluginReview, clearData) {
    (function(isPluginReview, checkData) {
    'use strict';

    var $ = jQuery,
    @@ -20,28 +20,54 @@
    },
    namespace,
    matchedStoredCollection,
    identifier,
    identifierClass = 'wp-duplicate-review-flag',
    message,
    messageClass = 'wp-duplicate-message',
    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));

    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) {
    identifier = $('<a class="bbp-topic-ip-info author-badge " href="' + matchedStoredCollection.url + '">Duplicate review</a>');
    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) {
    identifier.css({
    message.css({
    'background': 'red',
    'color': 'white',
    'fontWeight': '700',
    @@ -51,20 +77,14 @@
    'textDecoration': 'underline'
    });

    $('.bbp-topic-ip').append(identifier);
    $('.bbp-topic-ip').append(message);
    }
    } else {
    localStorage.setItem(namespace + reviewCollection.ip, JSON.stringify(reviewCollection));
    }
    }

    removeData.on('click', function() {
    clearData($, namespace);
    });

    $('.bbp-breadcrumb').prepend(removeData);

    })(isPluginReview, clearData);
    })(isPluginReview, checkData);

    function isPluginReview($) {
    'use strict';
    @@ -78,14 +98,35 @@ function isPluginReview($) {
    return false;
    }

    function clearData($, name) {
    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) {
    if (/^/ + name) {
    localStorage.removeItem(key);
    }
    check(key);
    });

    if (reviewData.length > 1) {
    return true;
    } else {
    return false;
    }
    }
  2. @anevins12 anevins12 revised this gist May 18, 2018. 1 changed file with 43 additions and 15 deletions.
    58 changes: 43 additions & 15 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -8,7 +8,7 @@
    // @grant none
    // ==/UserScript==

    (function(isPluginReview) {
    (function(isPluginReview, clearData) {
    'use strict';

    var $ = jQuery,
    @@ -18,37 +18,53 @@
    ip: 0,
    url: ''
    },
    flag,
    matchedStoredCollection;
    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;
    flag = 'wp-reviewee-';
    matchedStoredCollection = JSON.parse(localStorage.getItem(flag + reviewCollection.ip));

    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('<a class="bbp-topic-ip-info" href="' + matchedStoredCollection.url + '">Dupe</a>')
    .css({
    'color': 'red',
    'fontWeight': '700',
    'fontSize': '150%'
    });
    $('.bbp-topic-ip').append(identifier);
    }
    } else {
    localStorage.setItem(flag + reviewCollection.ip, JSON.stringify(reviewCollection));
    localStorage.setItem(namespace + reviewCollection.ip, JSON.stringify(reviewCollection));
    }
    }

    })(isPluginReview);
    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);
    }
    });
    }
  3. @anevins12 anevins12 created this gist May 18, 2018.
    63 changes: 63 additions & 0 deletions gistfile1.txt
    Original 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;
    }