Submit & status shortcuts

Replace a word in the URL and redirect to the new URL when Ctrl+Shift+S is pressed (Works only on Codeforces)

  1. // ==UserScript==
  2. // @name Submit & status shortcuts
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.100
  5. // @author khaled_eg ( https://codeforces.com/profile/khaled_eg )
  6. // @match https://codeforces.com/*
  7. // @grant none
  8. // @license MIT
  9. // @description Replace a word in the URL and redirect to the new URL when Ctrl+Shift+S is pressed (Works only on Codeforces)
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Function to replace the first occurrence of a word from the right in the URL
  16. function replaceWordInURL(wordToReplace, replacement) {
  17. let currentURL = window.location.href;
  18. let reversedURL = currentURL.split('').reverse().join('');
  19. let reversedWordToReplace = wordToReplace.split('').reverse().join('');
  20. let reversedReplacement = replacement.split('').reverse().join('');
  21. let reversedNewURL = reversedURL.replace(reversedWordToReplace, reversedReplacement);
  22. let newURL = reversedNewURL.split('').reverse().join('');
  23. return newURL;
  24. }
  25.  
  26. // Function to handle keydown event
  27. function handleKeyDown(event) {
  28. // Check if Ctrl+Shift+S is pressed
  29. if (event.ctrlKey && event.shiftKey && event.key === 'S') {
  30. // Check if the URL contains the word "problem"
  31. if (window.location.href.includes("problem")) {
  32. // Replace the first occurrence of "problem" with "submit"
  33. let newURL = replaceWordInURL("problem", "submit");
  34. // Redirect to the new URL
  35. window.location.href = newURL;
  36. } else {
  37. // If neither "problem" found, search for "status" and replace it with "submit"
  38. let newURL = replaceWordInURL("status", "submit");
  39. // Redirect to the new URL
  40. window.location.href = newURL;
  41. }
  42. }
  43. // Check if Ctrl+Shift+U is pressed
  44. if (event.ctrlKey && event.shiftKey && event.key === 'U') {
  45. // Check if the URL contains the word "problem"
  46. if (window.location.href.includes("problem")) {
  47. // Replace the first occurrence of "problem" with "status"
  48. let newURL = replaceWordInURL("problem", "status");
  49. // Check if "?friends=on" already exists at the end of the URL
  50. if (!newURL.includes("?friends=on")) {
  51. newURL += newURL.includes("?") ? "&friends=on" : "?friends=on";
  52. }
  53. // Redirect to the new URL
  54. window.location.href = newURL;
  55. } else if (window.location.href.includes("submit")) {
  56. // Replace the first occurrence of "submit" with "status"
  57. let newURL = replaceWordInURL("submit", "status");
  58. // Check if "?friends=on" already exists at the end of the URL
  59. if (!newURL.includes("?friends=on")) {
  60. newURL += newURL.includes("?") ? "&friends=on" : "?friends=on";
  61. }
  62. // Redirect to the new URL
  63. window.location.href = newURL;
  64. }
  65. }
  66. }
  67.  
  68. // Add event listener for keydown event
  69. document.addEventListener('keydown', handleKeyDown);
  70. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址