Highlight ep#

Highlight Episode Number

  1. // ==UserScript==
  2. // @name Highlight ep#
  3. // @namespace com.willian-zhang.highlight-eps
  4. // @version 1.04
  5. // @description Highlight Episode Number
  6. // @author Willian
  7. // @match http*://share.dmhy.org/*
  8. // @match http*://bangumi.moe/*
  9. // @match http*://share.xfsub.com*/sort-*
  10. // @require https://code.jquery.com/jquery-2.1.4.min.js
  11. // @grant unsafeWindow
  12. // @run-at document-end
  13. // ==/UserScript==
  14.  
  15. const angular = unsafeWindow.angular;
  16.  
  17. const colors = [
  18. "#FF0097",
  19. "#A200FF",
  20. "#00ABA9",
  21. "#8CBF26",
  22. "#E671B8",
  23. "#F09609",
  24. "#1BA1E2"
  25. ];
  26. const epRegex = /((.+)([\s|\[|【|第]))(\d{1,3}(?:\.\d)?(?:[-|~]\d{1,3})?)(([集|話|话|\s|\]|】])(.*))/;
  27.  
  28. const highlightMe = function(){
  29. let $element = $(this);
  30. if($element.html().match(/<highlight/)){
  31. return;
  32. }
  33. var text = $element.text().trim();
  34. var found = epRegex.exec(text);
  35. if(found !== null){
  36. let ep = Number(found[4]) >-1 ? Number(found[4]) : 0;
  37. let color = colors[ep % colors.length];
  38. $element.empty().append([
  39. document.createTextNode(found[1]),
  40. `<highlight style="background-color: ${color}">${found[4]}</highlight>`,
  41. document.createTextNode(found[5])
  42. ]);
  43. }else{
  44. console.log(text);
  45. }
  46. };
  47. if(/bangumi.moe/.test(document.location.host)){
  48. $(document).on("mouseenter",'[torrent-list]',function(e){
  49. let titleElements = $(this).find(".md-item-raised-title");
  50.  
  51. titleElements.find("span").each(highlightMe);
  52. titleElements.off("mouseenter");
  53. titleElements.on("mouseenter",highlightMe);
  54. });
  55. }else if(/share.dmhy.org/.test(document.location.host)){
  56. $(document).ready(function(){
  57. let table = $(".main > .table table > tbody");
  58. let titles = table.find('tr > td.title > a');
  59. titles.each(highlightMe);
  60. titles.off("mouseenter");
  61. titles.on("mouseenter",highlightMe);
  62. });
  63. }else if(/share.xfsub.com/.test(document.location.host)){
  64. $(document).ready(function(){
  65. let table = $("#listTable > tbody");
  66. let titles = table.find('tr > td:nth-child(2) > a:last-child');
  67. titles.each(highlightMe);
  68. titles.off("mouseenter");
  69. titles.on("mouseenter",highlightMe);
  70. });
  71. }
  72.