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
  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 fn_url(url){
  20. let obj_url=new URL(url);
  21. let params=obj_url.searchParams;
  22. return [obj_url,params];
  23. }
  24. (function() {
  25. 'use strict';
  26. let url=fn_url(document.location);
  27. let ary_img_web_type=["png","jpg","jpeg","gif","ico","bmp","svg","webp","avif","avifs","cur"];
  28. let a_link_list=document.querySelectorAll('td.react-directory-row-name-cell-large-screen a.Link--primary');
  29. let ary_img_href=[];
  30. for(let i=0;i<a_link_list.length;i++){//filter link
  31. let ary_split=a_link_list[i].textContent.split(".");
  32. if(ary_split.length>1){
  33. if(ary_img_web_type.includes(ary_split.pop())){
  34. //ary_img_href.push(a_link_list[i].textContent);
  35. ary_img_href.push(decodeURIComponent(a_link_list[i].href.replaceAll("/blob/","/raw/")).replaceAll(" ","%20"));
  36. }
  37. }
  38. }
  39. if(ary_img_href.length>0){
  40. let str_img_links="";
  41. let str_img_html_code="";
  42. for(let i=0;i<ary_img_href.length;i++){
  43. //str_img_links=str_img_links+"https://"+url[0].host+url[0].pathname.replaceAll("/tree/","/raw/")+"/"+ary_img_href[i]+"\n";
  44. str_img_links=str_img_links+ary_img_href[i]+"\n";
  45. str_img_html_code=str_img_html_code+"<img src=\""+ary_img_href[i]+"\"/>\n";
  46. }
  47. GM_registerMenuCommand("copy link("+ary_img_href.length+" img)", () =>{
  48. GM_setClipboard(str_img_links);
  49. });
  50. GM_registerMenuCommand("copy link(html format)", () =>{
  51. GM_setClipboard(str_img_html_code);
  52. });
  53. /*GM_registerMenuCommand("copy link(BBcode format)", () =>{
  54. });*/
  55. }
  56. })();