城通网盘 自动下载

5/29/2022, 3:57:37 PM

// ==UserScript==
// @name        城通网盘 自动下载
// @namespace   Forbidden Siren
// @author      Forbidden Siren
// @version     1.1.4
// @description 5/29/2022, 3:57:37 PM
// @grant	GM_openInTab
// @grant	GM_getValue
// @grant	GM_setValue
// @grant   GM_download
// @grant   unsafeWindow
// @grant   window.close
// @require https://greasyfork.org/scripts/448197-elementgetter/code/ElementGetter.js?version=1126009
// @connect      ctfile.com
// @connect      tv000.com
// @connect      tv001.com
// @connect      tv002.com
// @match       *://down.xiaolipan.com/*
// @match       *://*.089u.com/*
// @match       *://*.089m.com/*
// @match       *://*.306t.com/*
// @match       *://*.474b.com/*
// @match       *://*.51dr.cn/*
// @match       *://*.545c.com/*
// @match       *://*.545c.com/*
// @match       *://*.590m.com/*
// @match       *://*.72k.us/*
// @match       *://*.77ebooks.com/*
// @match       *://pan.bionav.cc/*
// @match       *://*.cfiles.com/*
// @match       *://*.cfiles.net/*
// @match       *://*.ctfile.com/*
// @match       *://*.ctfile.net/*
// @match       *://*.jdxiazai.cn/*
// @match       *://*.miaomiaoshuwu.com/*
// @match       *://*.n459.com/*
// @match       *://*.t00y.com/*
// @match       *://*.tc5.us/*
// @match       *://*.tmioe.com/*
// @match       *://*.u062.com/*
// @match       *://*.z701.com/*
// @match       *://t.94fbr.net/*
// @match       *://545c.com/*
// @match       *://*pan.cc/*
// @match       *://down.sxpdf.com/*
// ==/UserScript==

"use strict";

// const fileExt = [".epub",".azw4",".azw3",".azw2",".azw",".mobi"];
const fileExt = [".epub"];
const passcode = GM_getValue("passcode", "2023");

const elmGetter = new ElementGetter();
const options = { active: false, insert: true, setParent: true };
const close_time = 20 * 1000;
const next_time = 5 * 1000;

elmGetter.get('input#passcode').then(input => {
    let params = (new URL(document.location)).searchParams;
    let passwd = params.get('pwd');
    unsafeWindow.load_passcode();
    if(!input.value){
        input.value = passcode;
    }
    unsafeWindow.verify_passcode();

    elmGetter.get('#passcode-info.alert-warning', elm => {
        input.value = passcode;
        unsafeWindow.verify_passcode();
    });
});
elmGetter.get('[rv-href="file.vip_dx_url"]').then(elm => {
    format_title();
    if (isVisible(elm)) {
        download_file_click(elm);
    }
});
elmGetter.get(',card .btn-outline-secondary').then(down => {
    format_title();
});
function all_files() {
    elmGetter.get('#table_files_wrapper').then(table => {
        elmGetter.each('#table_files [role="row"] a', table, item => {
            fileExt.forEach(val => {
                if (item.text.endsWith(val)) {
                    GM_openInTab(item.href, options);
                }
            });
        });
        elmGetter.get('.paging_full_numbers #table_files_next a', table).then(elm => setTimeout(elm.click, next_time));
    });
}
elmGetter.get('.fs-error').then(window.close);

// all_files();

function format_title(){
    let title = document.title;
    title = title.replace(/ - \S+ 的分享/,'');
    if(title != document.title){
        document.title = title;
    }
}
function get_filename() {
    let filename = document.querySelector('.bg-gradient h4.text-white');
    filename = filename.textContent;
    filename = filename.replace("文件下载: ", "");
    return filename;
}

function timeout_close() {
    setInterval(window.close, close_time);
}
function download_file_click(elm) {
    elm.download = get_filename();
    window.location.href  = elm.href;
    // elm.click();
    timeout_close();
}
function download_use_gm(elm) {
    let filename = get_filename();
    const fileurl = elm.href;
    console.log(filename, fileurl);
    const options = {
        url: fileurl,
        name: filename,
        onload: timeout_close,
        // "onprogress": timeout_close,
        onerror: (err, detail) => {
            console.error(err, detail);
        },
    };
    GM_download(options);
}
function isVisible(e) {
    return !!(
        e.offsetParent ||
        e.offsetWidth ||
        e.offsetHeight ||
        e.getClientRects().length ||
        //  !(window.getComputedStyle(e).style.display === 'none')
        false
    );
}
/*
function isViewble(elem) {
  const style = getComputedStyle(elem);
  if (style.display === 'none') return false;
  if (style.visibility !== 'visible') return false;
  if (style.opacity < 0.1) return false;
  if (elem.offsetWidth + elem.offsetHeight + elem.getBoundingClientRect().height +
    elem.getBoundingClientRect().width === 0) {
    return false;
  }
  const elemCenter = {
    x: elem.getBoundingClientRect().left + elem.offsetWidth / 2,
    y: elem.getBoundingClientRect().top + elem.offsetHeight / 2
  };
  if (elemCenter.x < 0) return false;
  if (elemCenter.x > (document.documentElement.clientWidth || window.innerWidth)) return false;
  if (elemCenter.y < 0) return false;
  if (elemCenter.y > (document.documentElement.clientHeight || window.innerHeight)) return false;
  let pointContainer = document.elementFromPoint(elemCenter.x, elemCenter.y);
  do {
    if (pointContainer === elem) return true;
  } while (pointContainer = pointContainer.parentNode);
  return false;
}
*/