Skip Current Level

Clears specific content on a Webhek page

  1. // ==UserScript==
  2. // @name Skip Current Level
  3. // @namespace https://www.webhek.com/post/color-test/
  4. // @version 1.0
  5. // @description Clears specific content on a Webhek page
  6. // @match https://www.webhek.com/post/color-test/
  7. // @grant none
  8. // @author huoyuuuu
  9. // @homepage https://github.com/huoyuuu
  10. // @license the MIT license
  11. // ==/UserScript==
  12.  
  13.  
  14. (function () {
  15. function clearContent() {
  16. var targetSpan = getMostCommonStyledSpan(4, 8);
  17. removeSpansWithSameStyle(targetSpan.style);
  18. targetSpan = document.evaluate("/html/body/div[2]/div[2]/div/span[1]", document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue;
  19. targetSpan.click();
  20. }
  21.  
  22. function getMostCommonStyledSpan(startIndex, endIndex) {
  23. var spans = document.getElementsByTagName('span');
  24. var spanStyles = new Map();
  25. for (let i = startIndex - 1; i < Math.min(spans.length, endIndex); i++) {
  26. let styleText = spans[i].style.cssText;
  27. if (spanStyles.has(styleText)) {
  28. spanStyles.set(styleText, spanStyles.get(styleText) + 1);
  29. } else {
  30. spanStyles.set(styleText, 1);
  31. }
  32. }
  33.  
  34. var maxCount = 0;
  35. var targetSpanStyle = '';
  36. for (let [styleText, count] of spanStyles) {
  37. if (count > maxCount) {
  38. maxCount = count;
  39. targetSpanStyle = styleText;
  40. }
  41. }
  42.  
  43. for (let i = startIndex - 1; i < spans.length; i++) {
  44. if (spans[i].style.cssText === targetSpanStyle) {
  45. return spans[i];
  46. }
  47. }
  48. return null;
  49. }
  50.  
  51. function removeSpansWithSameStyle(targetStyle) {
  52. let spans = Array.from(document.getElementsByTagName('span'));
  53. spans.forEach(span => {
  54. if (span.style.cssText === targetStyle.cssText) {
  55. span.parentNode.removeChild(span);
  56. }
  57. });
  58. }
  59.  
  60. var button = document.createElement("button");
  61. button.innerHTML = "跳过本关";
  62. button.style.position = "fixed";
  63. button.style.top = "50%";
  64. button.style.right = "10px";
  65. button.style.zIndex = 1000;
  66. document.body.appendChild(button);
  67. button.addEventListener("click", clearContent);
  68. })();