Empornium: Name to tag search

Takes marked text and searches empornium

  1. // ==UserScript==
  2. // @name Empornium: Name to tag search
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.3
  5. // @description Takes marked text and searches empornium
  6. // @author Your Name
  7. // @match *://*/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=empornium.is
  9. // @grant GM_registerMenuCommand
  10. // @grant GM_openInTab
  11. // @grant GM_setClipboard
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. // Function to process text
  19. function processSelectedText() {
  20. const selectedText = window.getSelection().toString();
  21. if (!selectedText) {
  22. alert("Please select some text before using this command.");
  23. return null;
  24. }
  25. let processedText = selectedText.trim().toLowerCase().replace(/\s+/g, '.');
  26. return encodeURIComponent(processedText);
  27. }
  28.  
  29. // Navigate in current tab
  30. function navigateInCurrentTab() {
  31. const processedText = processSelectedText();
  32. if (processedText) {
  33. window.location.href = `https://www.empornium.is/torrents.php?order_by=seeders&order_way=desc&searchtext=&action=advanced&title=&sizeall=&sizetype=gb&sizerange=0.01&filelist=&taglist=${processedText}&autocomplete_toggle=on`;
  34. }
  35. }
  36.  
  37. // Open in new tab
  38. function openInNewTab() {
  39. const processedText = processSelectedText();
  40. if (processedText) {
  41. GM_openInTab(`https://www.empornium.is/torrents.php?order_by=seeders&order_way=desc&searchtext=&action=advanced&title=&sizeall=&sizetype=gb&sizerange=0.01&filelist=&taglist=${processedText}&autocomplete_toggle=on`, true);
  42. }
  43. }
  44.  
  45. // Register menu commands
  46. GM_registerMenuCommand("Emp (Ctrl+Alt+C)", navigateInCurrentTab, 'c');
  47. GM_registerMenuCommand("Emp in New Tab (Ctrl+Alt+N)", openInNewTab, 'n');
  48.  
  49. // Add keyboard shortcuts
  50. document.addEventListener('keydown', function(e) {
  51. if (e.ctrlKey && e.altKey && e.code === 'KeyN') {
  52. e.preventDefault();
  53. openInNewTab();
  54. } else if (e.ctrlKey && e.altKey && e.code === 'KeyC') {
  55. e.preventDefault();
  56. navigateInCurrentTab();
  57. }
  58. });
  59. })();