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. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل 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];
};