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).

目前為 2022-03-08 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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];
};