MDN Search Filtering

7/17/2020, 7:24:01 PM

当前为 2020-07-24 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name MDN Search Filtering
  3. // @namespace Violentmonkey Scripts
  4. // @match https://developer.mozilla.org/*
  5. // @grant none
  6. // @version 1.2
  7. // @author John Bussjaeger
  8. // @description 7/17/2020, 7:24:01 PM
  9. // @homepageURL https://github.com/bussdriver/MDN-enhancer
  10. // ==/UserScript==
  11.  
  12. var filters= ["all","api","addons","css","canvas","firefox","firefox-os","games","html","http","js","marketplace","mathml","mobile","apps","svg","webdev","standards","webext","webgl","docs","xpcom","xul"];
  13. var localized= {//map to filters + url + url_title
  14. 'en':["All"//special case
  15. ,"APIs and DOM","Add-ons & Extensions","CSS","Canvas","Firefox","Firefox OS","Games","HTML","HTTP","JavaScript","Marketplace","MathML","Mobile","Open Web Apps","SVG","Web Development","Web Standards","WebExtensions","WebGL","Writing Documentation","XPCOM","XUL"
  16. ,"Search Topics","http://kb.mozillazine.org/Using_keyword_searches","Keyword Searching"]
  17. };
  18. localized= localized[ navigator.language ] || localized[ navigator.language.split('-')[0] ] || localized.en;
  19.  
  20. //existing document elements:
  21. var form= document.getElementById('nav-main-search');
  22. var input= document.getElementById('main-q');
  23.  
  24. //CSS
  25. var style= getComputedStyle(form);
  26. document.styleSheets[0].insertRule('.search-results-filters {position: absolute;left:calc( '+ ( style.borderBottomLeftRadius ? style.borderBottomLeftRadius : style.paddingLeft +' + '+ style.borderLeftWidth +' + '+ style.borderLeftWidth ) +' );top: calc( '+ style.height +' - '+ style.borderBottomWidth +' );border:inherit;border-bottom-left-radius: inherit;border-bottom-right-radius: inherit;background-color: #fff;padding: 8px;z-index:9;}',0);
  27. document.styleSheets[0].insertRule('.search-results-filters label {display:block;padding-bottom:10px;}',0);
  28. document.styleSheets[0].insertRule('.page-header {z-index:1;}',0);
  29.  
  30. var fset= document.createElement('fieldset');
  31. fset.className= "search-results-filters";
  32. fset.style.display= "none";
  33. var legend= document.createElement('b');
  34. legend.appendChild(document.createTextNode( localized[localized.length-3] ));// "search topics"
  35. fset.appendChild(legend);
  36.  
  37. var checklist= [];
  38. var all;
  39. for(var item,check,x,i=0;i<filters.length;++i){
  40. x= filters[i];
  41. item= document.createElement('label');
  42. check= document.createElement('input');
  43. check.type= "checkbox";
  44. check.name= "topic";
  45. check.value= x;
  46. if( (location+'').indexOf('topic='+x) >=0 ){
  47. check.checked= true;
  48. }
  49. check.addEventListener('click',function(e){
  50. e.target.focus();//click should focus so submit can work
  51. },false);
  52. if(x==='all'){//"all" special case
  53. all= check;
  54. check.name='';
  55. if( (location+'').indexOf('topic=') === -1 ){
  56. check.checked= true;
  57. }
  58. check.addEventListener('change',function(e){
  59. if( e.target.checked ){
  60. for(var i=checklist.length;--i>=0;){
  61. checklist[i].checked=false;
  62. }
  63. }
  64. },false);
  65. }else{
  66. checklist.push(check);
  67. check.addEventListener('change',function(e){
  68. if( e.target.checked ){
  69. all.checked= false;
  70. }
  71. },false);
  72. }
  73. item.appendChild(check);
  74. item.appendChild(document.createTextNode(" "+ localized[i]));
  75. fset.appendChild(item);
  76. }
  77.  
  78. item = document.createElement('hr');
  79. fset.appendChild(item);
  80.  
  81. item = document.createElement('a');
  82. item.innerText= localized[localized.length-1];// "keyword searching"
  83. item.href= localized[localized.length-2];// url help on keyword searching
  84. fset.appendChild(item);
  85.  
  86. form.appendChild(fset);
  87. form.addEventListener('mouseover',function(){fset.style.display="block"},false);
  88. form.addEventListener('mouseout',function(){fset.style.display="none"},false);
  89.  
  90. input.setAttribute('autocomplete','off');
  91. input.addEventListener('focus',function(){fset.style.display="block"},false);

QingJ © 2025

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