Arrow Keys navigate Marketplace

This script makes it so you can navigate marketplace with arrow keys between next and previous pages. It also attemps to remove duplicates from results(highly imperfect).

Από την 08/03/2022. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==UserScript==
// @name         Arrow Keys navigate Marketplace
// @namespace    http://tampermonkey.net/
// @version      0.4
// @license      MIT
// @description  This script makes it so you can navigate marketplace with arrow keys between next and previous pages. It also attemps to remove duplicates from results(highly imperfect).
// @author       Aida Beorn
// @match        https://marketplace.secondlife.com/*
// @icon         https://www.google.com/s2/favicons?domain=secondlife.com
// @grant              None
// ==/UserScript==

function NextPage() {
	let next = document.getElementsByClassName('next_page')[0];
    if(next) {
        next.click();
    }
}

function PreviousPage() {
	let prev = document.getElementsByClassName('previous_page')[0];
    if(prev) {
        prev.click();
    }
}

function HandleKeyEvent(e) {
    switch(e.key) {
        case "ArrowRight":
            NextPage();
            break;
        case "ArrowLeft":
            PreviousPage();
            break;
    }
}

(function() {
    'use strict';

    document.addEventListener('keydown', HandleKeyEvent);
    RemoveDuplicates();
})();



function RemoveDuplicates() {
    let items1 = document.getElementsByClassName('gallery-item');
    let items2 = document.getElementsByClassName('gallery-item');
    let count = 0;

    for(let i = 0; i < items1.length; i++) {
        for(let k = 0; k < items2.length; k++) {
            const a = items1[i];
            const b = items2[k];
            const levDistance = levenshteinDistance(a.children[1].innerText, b.children[1].innerText);
            if(levDistance < 7 && i !== k) {
                //console.log(`${a.children[1].innerText}::${b.children[1].innerText}::${levDistance}`);
                b.remove();
                count++;
            }
        }
    }

    console.log(`Removed ${count} items`);
}

function levenshteinDistance(a, b){
  if(a.length == 0) return b.length;
  if(b.length == 0) return a.length;

  var matrix = [];

  // increment along the first column of each row
  var i;
  for(i = 0; i <= b.length; i++){
    matrix[i] = [i];
  }

  // increment each column in the first row
  var j;
  for(j = 0; j <= a.length; j++){
    matrix[0][j] = j;
  }

  // Fill in the rest of the matrix
  for(i = 1; i <= b.length; i++){
    for(j = 1; j <= a.length; j++){
      if(b.charAt(i-1) == a.charAt(j-1)){
        matrix[i][j] = matrix[i-1][j-1];
      } else {
        matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
                                Math.min(matrix[i][j-1] + 1, // insertion
                                         matrix[i-1][j] + 1)); // deletion
      }
    }
  }

  return matrix[b.length][a.length];
};