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 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Arrow Keys navigate Marketplace
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @license MIT
  6. // @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).
  7. // @author Aida Beorn
  8. // @match https://marketplace.secondlife.com/*
  9. // @icon https://www.google.com/s2/favicons?domain=secondlife.com
  10. // @grant none
  11. // ==/UserScript==
  12.  
  13. function NextPage() {
  14. let next = document.getElementsByClassName('next_page')[0];
  15. if(next) {
  16. next.click();
  17. }
  18. }
  19.  
  20. function PreviousPage() {
  21. let prev = document.getElementsByClassName('previous_page')[0];
  22. if(prev) {
  23. prev.click();
  24. }
  25. }
  26.  
  27. function HandleKeyEvent(e) {
  28. switch(e.key) {
  29. case "ArrowRight":
  30. NextPage();
  31. break;
  32. case "ArrowLeft":
  33. PreviousPage();
  34. break;
  35. }
  36. }
  37.  
  38. (function() {
  39. 'use strict';
  40.  
  41. document.addEventListener('keydown', HandleKeyEvent);
  42. RemoveDuplicates();
  43. })();
  44.  
  45.  
  46.  
  47. function RemoveDuplicates() {
  48. let items1 = document.getElementsByClassName('gallery-item');
  49. let items2 = document.getElementsByClassName('gallery-item');
  50. let count = 0;
  51.  
  52. for(let i = 0; i < items1.length; i++) {
  53. for(let k = 1; k < items2.length; k++) {
  54. const a = items1[i];
  55. const b = items2[k];
  56. const levDistance = levenshteinDistance(a.children[1].innerText, b.children[1].innerText);
  57. if(levDistance < 7) {
  58. //console.log(`${b.children[1].innerText}::${levDistance}`);
  59. b.remove();
  60. count++;
  61. }
  62. }
  63. }
  64.  
  65. console.log(`Removed ${count} items`);
  66. }
  67.  
  68. function levenshteinDistance(a, b){
  69. if(a.length == 0) return b.length;
  70. if(b.length == 0) return a.length;
  71.  
  72. var matrix = [];
  73.  
  74. // increment along the first column of each row
  75. var i;
  76. for(i = 0; i <= b.length; i++){
  77. matrix[i] = [i];
  78. }
  79.  
  80. // increment each column in the first row
  81. var j;
  82. for(j = 0; j <= a.length; j++){
  83. matrix[0][j] = j;
  84. }
  85.  
  86. // Fill in the rest of the matrix
  87. for(i = 1; i <= b.length; i++){
  88. for(j = 1; j <= a.length; j++){
  89. if(b.charAt(i-1) == a.charAt(j-1)){
  90. matrix[i][j] = matrix[i-1][j-1];
  91. } else {
  92. matrix[i][j] = Math.min(matrix[i-1][j-1] + 1, // substitution
  93. Math.min(matrix[i][j-1] + 1, // insertion
  94. matrix[i-1][j] + 1)); // deletion
  95. }
  96. }
  97. }
  98.  
  99. return matrix[b.length][a.length];
  100. };