copy img from repository host link

copy image link

  1. // ==UserScript==
  2. // @name copy img from repository host link
  3. // @description copy image link
  4. // @namespace github_Pic10_img
  5. // @author Covenant
  6. // @version 0.9.1
  7. // @license MIT
  8. // @homepage
  9. // @match https://github.com/*/tree/master
  10. // @match https://github.com/*/tree/master/*
  11. // @icon https://www.google.com/s2/favicons?sz=64&domain=github.com
  12. // @grant GM_setValue
  13. // @grant GM_getValue
  14. // @grant GM_registerMenuCommand
  15. // @grant GM_setClipboard
  16. // @run-at document-end
  17. // @noframes
  18. // ==/UserScript==
  19. function main_01(){
  20. let url=fn_url(document.location);
  21. let ary_img_web_type=["png","jpg","jpeg","gif","ico","bmp","svg","webp","avif","avifs","cur"];
  22. let a_link_list=document.querySelectorAll('td.react-directory-row-name-cell-large-screen a.Link--primary');
  23. let ary_img_href=[];
  24. for(let i=0;i<a_link_list.length;i++){//filter link
  25. let ary_split=a_link_list[i].textContent.split(".");
  26. if(ary_split.length>1){
  27. if(ary_img_web_type.includes(ary_split.pop())){
  28. //ary_img_href.push(a_link_list[i].textContent);
  29. ary_img_href.push(decodeURIComponent(a_link_list[i].href.replaceAll("/blob/","/raw/")).replaceAll(" ","%20"));
  30. }
  31. }
  32. }
  33. if(ary_img_href.length>0){
  34. let str_img_links="";
  35. let str_img_html_code="";
  36. for(let i=0;i<ary_img_href.length;i++){
  37. //str_img_links=str_img_links+"https://"+url[0].host+url[0].pathname.replaceAll("/tree/","/raw/")+"/"+ary_img_href[i]+"\n";
  38. str_img_links=str_img_links+ary_img_href[i]+"\n";
  39. str_img_html_code=str_img_html_code+"<img src=\""+ary_img_href[i]+"\"/>\n";
  40. }
  41. GM_registerMenuCommand("copy link("+ary_img_href.length+" img)", () =>{
  42. GM_setClipboard(str_img_links);
  43. });
  44. GM_registerMenuCommand("copy link(html format)", () =>{
  45. GM_setClipboard(str_img_html_code);
  46. });
  47. /*GM_registerMenuCommand("copy link(BBcode format)", () =>{
  48. });*/
  49. }else{return ary_img_href.length;}
  50. }
  51. function fn_url(url){
  52. let obj_url=new URL(url);
  53. let params=obj_url.searchParams;
  54. return [obj_url,params];
  55. }
  56. (function() {
  57. 'use strict';
  58. let int_check=main_01();
  59. if(int_check==0){
  60. window.setTimeout(( () => main_01() ), 5000);
  61. }
  62. })();