URL Based Search for Some Websites

If you enter required parameter in URL, it trigger a search on website. (URL example: https://subscene.com/subtitles/title?q=Avatar).

当前为 2021-05-31 提交的版本,查看 最新版本

此脚本不应直接安装。它是供其他脚本使用的外部库,要使用该库请加入元指令 // @require https://update.cn-greasyfork.org/scripts/427315/936409/URL%20Based%20Search%20for%20Some%20Websites.js

  1. // ==UserScript==
  2. // @name URL Based Search for Some Websites
  3. // @version 1.1
  4. // @description If you enter required parameter in URL, it trigger a search on website. (URL example: https://subscene.com/subtitles/title?q=Avatar).
  5. // @author nht.ctn
  6. // @namespace https://github.com/nhtctn
  7. // @include *://turktorrent.us/?p=torrents&pid=10&q=*
  8. // @include *://subscene.com/subtitles/title?q=*
  9. // @grant none
  10. // @run-at document-start
  11. // @icon https://turktorrent.us/favicon.ico?lv=2.2
  12. // ==/UserScript==
  13. const pageUrl = window.location.href;
  14. if (pageUrl.search(/https?:\/\/turktorrent\.us/) >= 0) {
  15. window.stop();
  16.  
  17. let urlParams = new URLSearchParams(window.location.search);
  18. let postKeyword = urlParams.get('q');
  19. let postUrl = 'https://turktorrent.us/?p=torrents&pid=10';
  20.  
  21. if (urlParams.get('q') && postKeyword !== '') {
  22. let postForm = document.createElement("form");
  23. postForm.setAttribute("method", "post");
  24. postForm.setAttribute("action", postUrl);
  25. let hiddenField = document.createElement("input");
  26. hiddenField.setAttribute("name", "keywords");
  27. hiddenField.setAttribute("value", postKeyword);
  28. hiddenField.setAttribute("type", "hidden");
  29. postForm.appendChild(hiddenField);
  30. let hiddenSelect = document.createElement("select");
  31. hiddenSelect.setAttribute("name", "search_type");
  32. let hiddenOpt = document.createElement("option");
  33. hiddenOpt.setAttribute("value", "name");
  34. hiddenSelect.appendChild(hiddenOpt);
  35. postForm.appendChild(hiddenSelect);
  36. console.log(postForm);
  37. document.getElementsByTagName('html')[0].appendChild(postForm);
  38. postForm.submit();
  39. }
  40. else {
  41. document.location = 'https://turktorrent.us/?p=torrents&pid=10';
  42. }
  43. }
  44. else if (pageUrl.search(/https?:\/\/subscene\.com/) >= 0) {
  45. window.stop();
  46.  
  47. let urlParams = new URLSearchParams(window.location.search);
  48. let postKeyword = urlParams.get('q');
  49. let postUrl = '/subtitles/searchbytitle';
  50.  
  51. if (urlParams.get('q') && postKeyword !== '') {
  52. let postForm = document.createElement("form");
  53. postForm.setAttribute("method", "post");
  54. postForm.setAttribute("action", postUrl);
  55. let hiddenField = document.createElement("input");
  56. hiddenField.setAttribute("name", "query");
  57. hiddenField.setAttribute("value", postKeyword);
  58. hiddenField.setAttribute("type", "hidden");
  59. postForm.appendChild(hiddenField);
  60. document.getElementsByTagName('html')[0].appendChild(postForm);
  61. postForm.submit();
  62. }
  63. else {
  64.  
  65. document.location = 'https://subscene.com/subtitles';
  66. }
  67. }