display_filename_on_image

with custom position, size, color

  1. // ==UserScript==
  2. // @name display_filename_on_image
  3. // @name:ja display_filename_on_image
  4. // @name:zh-TW display_filename_on_image
  5. // @name:zh-CN display_filename_on_image
  6. // @namespace display_filename_on_image
  7. // @supportURL https://github.com/zhuzemin
  8. // @description:zh-CN with custom position, size, color
  9. // @description:zh-TW with custom position, size, color
  10. // @description:ja with custom position, size, color
  11. // @description with custom position, size, color
  12. // @include https://*
  13. // @include http://*
  14. // @version 1.0
  15. // @grant GM_xmlhttpRequest
  16. // @grant GM_registerMenuCommand
  17. // @grant GM_setValue
  18. // @grant GM_getValue
  19. // @run-at document-end
  20. // @author zhuzemin
  21. // @license Mozilla Public License 2.0; http://www.mozilla.org/MPL/2.0/
  22. // @license CC Attribution-ShareAlike 4.0 International; http://creativecommons.org/licenses/by-sa/4.0/
  23. // ==/UserScript==
  24. let textPosition={
  25. bottom_left:`
  26. bottom: 8px;
  27. left: 16px;
  28. `,
  29. top_left:`
  30. top: 8px;
  31. left: 16px;
  32. `,
  33. top_right:`
  34. top: 8px;
  35. right: 16px;
  36. `,
  37. bottom_right:`
  38. bottom: 8px;
  39. right: 16px;
  40. `,
  41. centered :`
  42. top: 50%;
  43. left: 50%;
  44. transform: translate(-50%, -50%);
  45. `
  46. }
  47. var config = {
  48. 'debug': false,
  49. 'targetImgSize':['260x146','260x289'],
  50. //'targetImgSize':['16x16','40x40','96x96'],
  51. 'color':'black',
  52. 'size':'100%',
  53. 'position':textPosition.centered
  54. }
  55. var debug = config.debug ? console.log.bind(console) : function () {
  56. };
  57.  
  58. // setting User Preferences
  59. function setUserPref(varName, defaultVal, menuText, promtText, sep){
  60. GM_registerMenuCommand(menuText, function() {
  61. var val = prompt(promtText, GM_getValue(varName, defaultVal));
  62. if (val === null) { return; } // end execution if clicked CANCEL
  63. // prepare string of variables separated by the separator
  64. if (sep && val){
  65. var pat1 = new RegExp('\\s*' + sep + '+\\s*', 'g'); // trim space/s around separator & trim repeated separator
  66. var pat2 = new RegExp('(?:^' + sep + '+|' + sep + '+$)', 'g'); // trim starting & trailing separator
  67. //val = val.replace(pat1, sep).replace(pat2, '');
  68. }
  69. //val = val.replace(/\s{2,}/g, ' ').trim(); // remove multiple spaces and trim
  70. GM_setValue(varName, val);
  71. // Apply changes (immediately if there are no existing highlights, or upon reload to clear the old ones)
  72. //if(!document.body.querySelector(".THmo")) THmo_doHighlight(document.body);
  73. //else location.reload();
  74. });
  75. }
  76. // prepare UserPrefs
  77. setUserPref(
  78. 'tags',
  79. 'chinese;',
  80. 'Set Highlight Tags',
  81. `Set Highlight Tags, split with ";". Example: "mmf threesome; chinese"`,
  82. ','
  83. );
  84.  
  85.  
  86. var init = function () {
  87. let imgList=document.querySelectorAll('img');
  88. for(var img of imgList){
  89. let imgSize=img.width+'x'+img.height;
  90. debug('imgSize: '+imgSize);
  91. if(config.targetImgSize.includes(imgSize)){
  92. if(img.src!=null){
  93. let filename=img.src.match(/([^/]*)$/)[1];
  94. debug('filename: '+filename);
  95. let div=document.createElement('div');
  96. div.style=`
  97. position: absolute;
  98. font-size:`+config.size+`;
  99. color:`+config.color+`;
  100. `+config.position;
  101. debug('div.style: '+div.style);
  102. div.innerText=filename;
  103. img.parentElement.style='position: relative!important;';
  104. img.parentElement.insertBefore(div,null);
  105. }
  106.  
  107. }
  108. }
  109. }
  110.  
  111. window.addEventListener('load', init);

QingJ © 2025

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