Sleazy Fork is available in English.

Automatic copying the photo URL to clipboard in PhotoBucket album

If the result is not complete, please increase the Delay time。

Verzia zo dňa 05.05.2018. Pozri najnovšiu verziu.

// ==UserScript==
// @name         Automatic copying the photo URL to clipboard in PhotoBucket album
// @name:zh-TW   自動複製PhotoBucket圖片URL至剪貼板
// @namespace    http://WWW.NTRSN.CN/
// @version      0.1
// @description  If the result is not complete, please increase the Delay time。
// @description:zh-tw 若是結果不完整請提高延時
// @note         I'm sorry.I took a lot of times.But The function of save as TXT just not work :( Can you tell me what's the wrong???
// @author       WWW.NTRSN.CN
// @match        http://s50.photobucket.com/*/library/*
// @require      https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/1.3.3/FileSaver.min.js
// @supportURL   873248164@qq.com
// @contributionURL https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=873248164@qq.com&item_name=Greasy+Fork+donation
// @grant        GM_addStyle
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_listValues
// @grant        GM_deleteValue
// @grant        GM_registerMenuCommand
// @grant        GM_setClipboard
// @compatible   chrome
// @compatible   firefox
// @compatible   opera 未測試not test
// @compatible   safari 未測試not test
// ==/UserScript==

(function() {

    'use strict';
    // Your code here...
    /*jshint multistr: true */
    var tipStyle = "\
#dashboard {position:fixed;top:20px;right:20px;width:440px;height:auto;background-color:#fff;border:1px solid #000;padding:0px 30px 0px 30px;z-index:999}\
#dashboard h1{height:52px;line-height:52px;text-align:center;}\
#dashboard div{font-size:14px;}\
#dashboard fieldset{border:1px solid #ccc;padding:8px 12px;line-height:32px;}\
#dashboard fieldset legend{font-weight:700}\
#dashboard label{width:50px;text-align:left;display:inline;}\
#dashboard input{width:80px;margin-top:10px;}\
";
    GM_addStyle(tipStyle);
    function Setting()
    {
        var d = document;
        var div = d.createElement('div');
        div.id = 'dashboard';
        div.innerHTML = "\
<h1>設定Setting</h1>\
<ol id='dol'>\
</ol>\
<fieldset>\
<center><legend>設定複製類型Setting the copy type</legend></center>\
<label for='Direct'>Direct</label> <input id='Direct' type='checkbox' value='Direct'>\
<label for='HTML '>HTML</label> <input id='HTML' type='checkbox' value='HTML'>\
<label for='IMG'>IMG codes</label> <input id='IMG' type='checkbox' value='IMG'><br />\
<center><label>類型是:Type is:</label>&nbsp;<input id='Type' type='text'></center>\
</fieldset>\
<fieldset>\
<center><legend>設定延時時間Setting the Delay time</legend></center>\
&emsp;&emsp;&emsp;<label for='RunningDelay'>加載腳本Load script</label>&nbsp;<input id='RunningDelay' type='text'>&nbsp;<label for='RunningDelay'>毫秒 millisecond</label><br />\
&emsp;&emsp;&emsp;<label for='organizerHandleDelay'>點擊圖片First Image</label>&nbsp;<input id='organizerHandleDelay' type='text'>&nbsp;<label for='organizerHandleDelay'>毫秒 millisecond</label><br />\
&emsp;&emsp;&emsp;<label for='selectallButtonDelay'>點擊全選Full Select</label>&nbsp;<input id='selectallButtonDelay' type='text'>&nbsp;<label for='selectallButtonDelay'>毫秒 millisecond</label><br />\
&emsp;&emsp;&emsp;<label for='iconlinkDelay'>點擊連結Link Button</label>&nbsp;<input id='iconlinkDelay' type='text'>&nbsp;<label for='iconlinkDelay'>毫秒 millisecond</label><br />\
&emsp;&emsp;&emsp;<label for='CopyDelay'>複製連結Copy Links</label>&nbsp;<input id='CopyDelay' type='text'>&nbsp;<label for='CopyDelay'>毫秒 millisecond</label><br />\
<center><input id='SetDelay' type='button' value='確定OK'></center>\
</fieldset>\
<input id='clos' type='button' value='關閉Close' onclick=\"document.body.removeChild(document.getElementById('dashboard'))\">&emsp;&emsp;&emsp;<label for='TXT'>是否下載TXT檔案Whether save as TXT</label><input id='TXT' type='checkbox'>\
";
        d.body.appendChild(div);
        document.getElementById('Type').value=GM_getValue('TYPE');
        document.getElementById(GM_getValue('TYPE')).checked=true;
        document.getElementById('RunningDelay').value=GM_getValue('RunningDelay');
        document.getElementById('organizerHandleDelay').value=GM_getValue('organizerHandleDelay');
        document.getElementById('selectallButtonDelay').value=GM_getValue('selectallButtonDelay');
        document.getElementById('iconlinkDelay').value=GM_getValue('iconlinkDelay');
        document.getElementById('CopyDelay').value=GM_getValue('CopyDelay');
        /*if(GM_getValue('TXT')==true)//**************It's not work*******************
        {
            alert(GM_getValue('ATXT=true'));
            document.getElementById('TXT').checked='true';
        }*/
        document.getElementById('SetDelay').addEventListener('click',function(){
            var RunningDelay=document.getElementById('RunningDelay').value;
            var organizerHandleDelay=document.getElementById('organizerHandleDelay').value;
            var selectallButtonDelay=document.getElementById('selectallButtonDelay').value;
            var iconlinkDelay=document.getElementById('iconlinkDelay').value;
            var CopyDelay=document.getElementById('CopyDelay').value;
            if(!isNaN(RunningDelay)&&RunningDelay!==''&&!isNaN(organizerHandleDelay)&&organizerHandleDelay!==''&&!isNaN(selectallButtonDelay)&&selectallButtonDelay!==''&&!isNaN(iconlinkDelay)&&iconlinkDelay!==''&&!isNaN(CopyDelay)&&CopyDelay!=='')
            {
                GM_setValue('RunningDelay',RunningDelay);
                GM_setValue('organizerHandleDelay',organizerHandleDelay);
                GM_setValue('selectallButtonDelay',selectallButtonDelay);
                GM_setValue('iconlinkDelay',iconlinkDelay);
                GM_setValue('CopyDelay',CopyDelay);
                alert('設定成功哦 Set up success!');
            }
            else
            {
                alert('您沒有設定延遲時間哦 You are not yet setting delay time!');
            }
        },false);
        document.getElementById('RunningDelay').addEventListener('click',function(){
            var RunningDelay=document.getElementById('RunningDelay').value;
            if(RunningDelay=='undefined')
            {

                document.getElementById('RunningDelay').value='';
            }

        },false);
        document.getElementById('organizerHandleDelay').addEventListener('click',function(){
            var organizerHandleDelay=document.getElementById('organizerHandleDelay').value;
            if(organizerHandleDelay=='undefined')
            {
                document.getElementById('organizerHandleDelay').value='';
            }
        },false);
        document.getElementById('selectallButtonDelay').addEventListener('click',function(){
            var selectallButtonDelay=document.getElementById('selectallButtonDelay').value;
            if(selectallButtonDelay=='undefined')
            {
                document.getElementById('selectallButtonDelay').value='';
            }
        },false);
        document.getElementById('iconlinkDelay').addEventListener('click',function(){
            var iconlinkDelay=document.getElementById('iconlinkDelay').value;
            if(iconlinkDelay=='undefined')
            {
                document.getElementById('iconlinkDelay').value='';
            }
        },false);
        /*document.getElementById('TXT').addEventListener('click',function(){**************It's not work*******************
            var TXT= document.getElementById('TXT');
            if(GM_getValue('TXT')==false||TXT.checked!=='true')
            {
                GM_setValue('TXT',true);
            }
            else
            {
                GM_setValue('TXT',false);
            }
        },false);*/
        if(GM_getValue('TXT')=='true')
        {   setTimeout(function(){
            alert('TXT');alert('TXT');alert('TXT');alert('TXT');
            document.getElementById('TXT').checked='true';
        },3000);
        }
        document.getElementById('CopyDelay').addEventListener('click',function(){
            var CopyDelay=document.getElementById('CopyDelay').value;
            if(CopyDelay=='undefined')
            {
                document.getElementById('CopyDelay').value='';
            }
        },false);

        document.getElementById('Direct').addEventListener('click',function() {
            Event('Direct');
        },false);
        document.getElementById('HTML').addEventListener('click',function(){
            Event('HTML');
        },false);
        document.getElementById('IMG').addEventListener('click',function(){
            Event('IMG');
        },false);


        function Event(id)
        {
            if(GM_getValue('TYPE')=='undefined')
            {
                GM_setValue('TYPE',id);
            }
            else if(GM_getValue('TYPE')!=='undefined'&&GM_getValue('TYPE')!==id)
            {
                document.getElementById(GM_getValue('TYPE')).checked=false;
                GM_setValue('TYPE',id);
                /* GM_setValue('Direct','Direct');GM_setValue('HTML','HTML');GM_setValue('IMG','IMG');**************It's an old approach*******************
                var list=GM_listValues();
                GM_deleteValue(id);
                for(var i in list)
                {
                    if(list[i]==GM_getValue('TYPE')||list[i]==GM_getValue('Delay'))
                    {
                        continue;
                    }
                    else
                    {
                        document.getElementById(GM_getValue(list[i])).checked=false;
                    }
                }*/
            }
            else
            {
                document.getElementById(id).checked=false;
                GM_setValue('TYPE','undefined');
            }
            document.getElementById('Type').value=GM_getValue('TYPE');
        }


        /* Array.prototype.removeByValue = function(val) {**************It's an old approach and not work*******************
            for(var i=0; i<this.length; i++) {
                if(this[i] == val) {
                    this.splice(i, 1);
                    break;
                }
            }
        };var type=new Array('Direct','HTML','IMG');type.RemoveByValue(id);*/
    }
    function GetType()
    {
        var Type;
        if(typeof(GM_getValue('TYPE'))!==undefined)
        {
            Type=GM_getValue('TYPE');
        }

        else{
            alert('您沒有設定複製類型哦You are  not yet set the copy type!');
        }
        return Type;
    }
    function AUTOCOPY(organizerHandle,selectallButton,iconlink)
    {
        setTimeout(function(){
            //for(var i in organizerHandle)
            //{
            organizerHandle[0].click();
            //}
        },GM_getValue('organizerHandleDelay'));
        setTimeout(function(){
            selectallButton.click();
        },GM_getValue('selectallButtonDelay'));
        setTimeout(function(){
            iconlink.click();
        },GM_getValue('iconlinkDelay'));
        setTimeout(function(){
            var Type =GetType();
            var lable='bulk_link_modal_ccinput_';
            var Values;

            switch (Type)
            {
                case  'Direct':
                    Values=document.getElementById(lable+'0').value;
                    break;
                case  'HTML':
                    Values=document.getElementById(lable+'1').value;
                    break;
                case  'IMG':
                    Values=document.getElementById(lable+'2').value;
                    break;
            }
            GM_setClipboard(Values);
            if(typeof(Values)!=='undefined'|| Values !== null || Values !== ""){
                alert('複製成功。值為Copy successful!The data is:\n\n'+Values);
                //if(GM_getValue('TXT')==true)**************It's not work:(*******************
                //{
                SaveToTXT(Values);
                //}
            }
            else
            {
                alert('複製失敗哦Copy failed!\n'+Values);
            }
            document.getElementById('bulkLinkModal').style.visibility='hidden';
        },GM_getValue('CopyDelay'));

    }
    function Click()
    {
        window.onload=function(){
            var organizerHandle=document.getElementsByClassName('organizerHandle');
            var  selectallButton=document.getElementById('selectallButton');
            var  iconlink=document.getElementsByClassName('icon-link')[0];
            do{
                AUTOCOPY(organizerHandle,selectallButton,iconlink);
            }
            while(typeof(typeof(organizerHandle)=='undefined'||selectallButton)=='undefined'||typeof(iconlink)=='undefined');
        };
    }
    function SaveToTXT(values)
    {
        var title=document.getElementsByClassName('rw editable-field')[1].innerHTML.replace(/^\s*|\s*$/g, "");
        var blob = new Blob([values], {type: "text/plain;charset=utf-8"});
        saveAs(blob,title+".txt");
    }
    GM_registerMenuCommand('設定複製類型 Setting the copy type',Setting,"s");
    setTimeout(function(){
        Click();
    },GM_getValue('RunningDelay'));
})();