copy img from repository host link

copy image link

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         copy img from repository host link
// @description  copy image link
// @namespace    github_Pic10_img
// @author       Covenant
// @version      0.9.1
// @license      MIT
// @homepage
// @match        https://github.com/*/tree/master
// @match        https://github.com/*/tree/master/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=github.com
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// @run-at       document-end
// @noframes
// ==/UserScript==
function main_01(){
    let url=fn_url(document.location);
    let ary_img_web_type=["png","jpg","jpeg","gif","ico","bmp","svg","webp","avif","avifs","cur"];
    let a_link_list=document.querySelectorAll('td.react-directory-row-name-cell-large-screen a.Link--primary');
    let ary_img_href=[];
    for(let i=0;i<a_link_list.length;i++){//filter link
        let ary_split=a_link_list[i].textContent.split(".");
        if(ary_split.length>1){
            if(ary_img_web_type.includes(ary_split.pop())){
                //ary_img_href.push(a_link_list[i].textContent);
                ary_img_href.push(decodeURIComponent(a_link_list[i].href.replaceAll("/blob/","/raw/")).replaceAll(" ","%20"));
            }
        }
    }
    if(ary_img_href.length>0){
        let str_img_links="";
        let str_img_html_code="";
        for(let i=0;i<ary_img_href.length;i++){
            //str_img_links=str_img_links+"https://"+url[0].host+url[0].pathname.replaceAll("/tree/","/raw/")+"/"+ary_img_href[i]+"\n";
            str_img_links=str_img_links+ary_img_href[i]+"\n";
            str_img_html_code=str_img_html_code+"<img src=\""+ary_img_href[i]+"\"/>\n";
        }
        GM_registerMenuCommand("copy link("+ary_img_href.length+" img)", () =>{
            GM_setClipboard(str_img_links);
        });
        GM_registerMenuCommand("copy link(html format)", () =>{
            GM_setClipboard(str_img_html_code);
        });
        /*GM_registerMenuCommand("copy link(BBcode format)", () =>{
        });*/
    }else{return ary_img_href.length;}
}
function fn_url(url){
    let obj_url=new URL(url);
    let params=obj_url.searchParams;
    return [obj_url,params];
}
(function() {
    'use strict';
    let int_check=main_01();
    if(int_check==0){
        window.setTimeout(( () => main_01() ), 5000);
    }
})();