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 提交的版本,檢視 最新版本

此腳本不應該直接安裝,它是一個供其他腳本使用的函式庫。欲使用本函式庫,請在腳本 metadata 寫上: // @require https://update.cn-greasyfork.org/scripts/427315/936408/URL%20Based%20Search%20for%20Some%20Websites.js

  1. // ==UserScript==
  2. // @name URL Based Search for Some Websites
  3. // @version 1.0
  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.  
  16. let urlParams = new URLSearchParams(window.location.search);
  17. let postKeyword = urlParams.get('q');
  18. let postUrl = 'https://turktorrent.us/?p=torrents&pid=10';
  19.  
  20. if (urlParams.get('q') && postKeyword !== '') {
  21. let postForm = document.createElement("form");
  22. postForm.setAttribute("method", "post");
  23. postForm.setAttribute("action", postUrl);
  24. let hiddenField = document.createElement("input");
  25. hiddenField.setAttribute("name", "keywords");
  26. hiddenField.setAttribute("value", postKeyword);
  27. hiddenField.setAttribute("type", "hidden");
  28. postForm.appendChild(hiddenField);
  29. let hiddenSelect = document.createElement("select");
  30. hiddenSelect.setAttribute("name", "search_type");
  31. let hiddenOpt = document.createElement("option");
  32. hiddenOpt.setAttribute("value", "name");
  33. hiddenSelect.appendChild(hiddenOpt);
  34. postForm.appendChild(hiddenSelect);
  35. console.log(postForm);
  36. document.getElementsByTagName('html')[0].appendChild(postForm);
  37. postForm.submit();
  38. }
  39. else {
  40. document.location = 'https://turktorrent.us/?p=torrents&pid=10';
  41. }
  42. }
  43. else if (pageUrl.search(/https?:\/\/subscene\.com/) >= 0) {
  44. window.stop();
  45.  
  46. let urlParams = new URLSearchParams(window.location.search);
  47. let postKeyword = urlParams.get('q');
  48. let postUrl = '/subtitles/searchbytitle';
  49.  
  50. if (urlParams.get('q') && postKeyword !== '') {
  51. let postForm = document.createElement("form");
  52. postForm.setAttribute("method", "post");
  53. postForm.setAttribute("action", postUrl);
  54. let hiddenField = document.createElement("input");
  55. hiddenField.setAttribute("name", "query");
  56. hiddenField.setAttribute("value", postKeyword);
  57. hiddenField.setAttribute("type", "hidden");
  58. postForm.appendChild(hiddenField);
  59. document.getElementsByTagName('html')[0].appendChild(postForm);
  60. postForm.submit();
  61. }
  62. else {
  63.  
  64. document.location = 'https://subscene.com/subtitles';
  65. }
  66. }