IMDb - Set default user reviews sorting

Select which sorting option should be used by default when click on a link "User reviews"

  1. // ==UserScript==
  2. // @name IMDb - Set default user reviews sorting
  3. // @namespace https://github.com/Procyon-b
  4. // @version 0.5
  5. // @description Select which sorting option should be used by default when click on a link "User reviews"
  6. // @author Achernar
  7. // @include /^https:\/\/www\.imdb\.com\/title\/[^\/]+\/(reference\/?)?(\?.*)?$/
  8. // @run-at document-end
  9. // @grant GM_getValue
  10. // @grant GM_setValue
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. "use strict";
  15.  
  16. var L, sort, c={ 'helpfulnessScore':'Helpfulness', 'submissionDate':'Review date', 'totalVotes':'Total votes', 'reviewVolume':'Prolific reviewer', 'userRating':'Review rating'};
  17.  
  18. function fix() {
  19. L=document.querySelectorAll('a[href*="/title/"][href*="/reviews"], a[href^="reviews"]');
  20. sort=GM_getValue('sort','helpfulnessScore');
  21.  
  22. L.forEach(function(e){
  23. let H=e.href.split('?');
  24. if (!H[0].endsWith('reviews') && !H[0].endsWith('reviews/')) return;
  25. let s=H[1] || '';
  26. let r=[];
  27. s.split('&').forEach(function(e){
  28. var p=e.split('=');
  29. if (p[0]) r[p.shift().trim()]=p.join('=');
  30. });
  31. if (sort=='unset') delete r.sort;
  32. else r.sort=sort;
  33. let r2=[];
  34. for (let k in r) { r2.push(k+'='+r[k]); }
  35.  
  36. H[1]=r2.join('&');
  37. if (H[1]=='') H.pop();
  38. e.href=H.join('?');
  39. });
  40.  
  41. }
  42.  
  43. fix();
  44.  
  45.  
  46. var dialog=document.createElement('div');
  47. dialog.id='fix_def_sort';
  48. dialog.innerHTML=`<style>
  49. #fix_def_sort {
  50. position: absolute;
  51. color: black;
  52. background-color:white;
  53. top: 4em;
  54. z-index: 100 !important;
  55. font-size: 13px;
  56. font-family: arial;
  57. padding: 3px 8px;
  58. border: 2px solid gray;
  59. min-width: 23em;
  60. text-align: left;
  61. }
  62. #fix_def_sort, #fix_def_sort * {
  63. white-space: nowrap;
  64. }
  65. #fix_def_sort #close {
  66. float: right;
  67. color: red;
  68. cursor: pointer;
  69. z-index: 10;
  70. }
  71. .reviewSortSettings {
  72. position: relative !important;
  73. }
  74. </style><b>Select default user reviews sorting</b> &nbsp; <div id="close">&#10062;</div><br>
  75. <select><option value="unset">[ unset ]</option></select>
  76. `;
  77.  
  78. dialog.querySelector('#close').onclick=function(){
  79. dialog.parentNode.classList.toggle('reviewSortSettings',false);
  80. dialog.remove();
  81. };
  82.  
  83. var E, sel=dialog.querySelector('select');
  84. if (sel) {
  85. for (let k in c) {
  86. sel.innerHTML+='<option value="'+k+'"'+(k==sort?' selected':'')+'>'+c[k]+'</option>';
  87. }
  88. sel.onchange=function(){
  89. GM_setValue('sort',this.value);
  90. fix();
  91. }
  92. }
  93.  
  94. if (L.length)
  95. for (let i=0; E=L[i]; i++) {
  96. E.addEventListener('click', function(ev){
  97. if (ev.ctrlKey && ev.altKey) {
  98. this.parentNode.appendChild(dialog);
  99. this.parentNode.classList.toggle('reviewSortSettings',true);
  100. ev.preventDefault();
  101. ev.stopPropagation();
  102. }
  103. }, {capture:true});
  104. }
  105.  
  106.  
  107. })();

QingJ © 2025

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