Greasy Fork

Greasy Fork is available in English.

蓝奏云重定向+记住密码

自动将所有蓝奏云链接重定向至lanzn.com。自动记住并填写蓝奏云密码。直接下载APK文件。

目前为 2024-03-16 提交的版本,查看 最新版本

// ==UserScript==
// @name         蓝奏云重定向+记住密码
// @namespace    http://greasyfork.icu/zh-CN/scripts?set=589091
// @version      1.21
// @description  自动将所有蓝奏云链接重定向至lanzn.com。自动记住并填写蓝奏云密码。直接下载APK文件。
// @author       呆呆
// @match        https://*lanzou*.com/*
// @match        https://*lanosso.com/*
// @match        https://*lanzog.com/*
// @match        https://*lanpw.com/*
// @match        https://*lanpv.com/*
// @match        https://*lanzv.com/*
// @match        https://*lanzn.com/*
// @match        https://m-load.lanrar.com/*
// @grant        GM_registerMenuCommand
// @grant        GM_setValue
// @grant        GM_getValue
// @grant        GM_listValues
// @grant        GM_deleteValue
// @grant        GM_notification
// ==/UserScript==

if (document.getElementById('fix')) {
    if (typeof(window.via) == "object") window.via.toast('正在下载....');
    else if (typeof(window.mbrowser) == "object") window.mbrowser.showToast('正在下载....');

    return;
}

function addElement({
    tag,
    attrs = {},
    to = document.body || document.documentElement,
}) {
    const el = document.createElement(tag);
    Object.assign(el, attrs);
    to.appendChild(el);
    return el;
}

function addStyle(css) {
    return addElement({
        tag: 'style',
        attrs: {
            textContent: css,
        },
        to: document.head,
    });
}

var config = {
    "toast": 0.1,
    "out": 1
};

function toast(text, time = 3, callback, transition = 0.2) {
    let isObj = (o) => typeof o == 'object' && typeof o.toString == 'function' && o.toString() === '[object Object]', timeout, toastTransCount = 0;
    if (typeof text != 'string') text = String(text);
    if (typeof time != 'number' || time <= 0) time = 3;
    if (typeof transition != 'number' || transition < 0) transition = 0.2;
    if (callback && !isObj(callback)) callback = undefined;
    if (callback) {
        if (callback.text && typeof callback.text != 'string') callback.text = String(callback.text);
        if (
        callback.color && (typeof callback.color != 'string' || callback.color === '')) delete callback.color;
        if (callback.onclick && typeof callback.onclick != 'function') callback.onclick = () => null;
        if (callback.onclose && typeof callback.onclose != 'function') delete callback.onclose;
    }

    let toastStyle = addStyle(`
  #bextToast {
    all: initial;
    display: flex;
    position: fixed;
    left: 0;
    right: 0;
    bottom: 10vh;
    width: max-content;
    max-width: 80vw;
    max-height: 80vh;
    margin: 0 auto;
    border-radius: 20px;
    padding: .5em 1em;
    font-size: 16px;
    background-color: rgba(0,0,0,0.5);
    color: white;
    z-index: 1000002;
    opacity: 0%;
    transition: opacity ${transition}s;
  }
  #bextToast > * {
    display: -webkit-box;
    height: max-content;
    margin: auto .25em;
    width: max-content;
    max-width: calc(40vw - .5em);
    max-height: 80vh;
    overflow: hidden;
    -webkit-line-clamp: 22;
    -webkit-box-orient: vertical;
    text-overflow: ellipsis;
    overflow-wrap: anywhere;
  }
  #bextToastBtn {
    color: ${callback && callback.color ? callback.color : 'turquoise'}
  }
  #bextToast.bextToastShow {
    opacity: 1;
  }
    `),
    toastDiv = addElement({
        tag: 'div',
        attrs: {
            id: 'bextToast',
        },
    }),
    toastShow = () => {
        toastDiv.classList.toggle('bextToastShow');
        toastTransCount++;
        if (toastTransCount >= 2) {
            setTimeout(function() {
                toastDiv.remove();
                toastStyle.remove();
                if (callback && callback.onclose) callback.onclose.call(this);
            }, transition * 1000 + 1);
        }
    };
    addElement({
        tag: 'div',
        attrs: {
            id: 'bextToastText',
            innerText: text,
        },
        to: toastDiv,
    });
    if (callback && callback.text) {
        addElement({
            tag: 'div',
            attrs: {
                id: 'bextToastBtn',
                innerText: callback.text,
                onclick: callback && callback.onclick ? () => {
                    callback.onclick.call(this);
                    clearTimeout(timeout);
                    toastShow();
                } : null,
            },
            to: toastDiv,
        });
    }
    setTimeout(toastShow, 1);
    timeout = setTimeout(toastShow, (time + transition * 2) * 1000);
}

function Toast(text) {
    if (typeof(window.via) == "object") window.via.toast(text);
    else toast(text);
}

// 获取当前网页链接
var currentUrl = window.location.href;

// 检查当前网址
if (!currentUrl.startsWith('https://www.lanzn.com/')) {
    // 替换域名
    var newUrl = currentUrl.replace(window.location.hostname, 'www.lanzn.com');

    Toast("重定向中....");

    // 重新访问新链接
    window.location.href = newUrl;
}

// 使用GM_registerMenuCommand添加管理密码的菜单命令
GM_registerMenuCommand('查看密码', function() {
    // 获取所有存储的键
    const allKeys = GM_listValues();
    // 存储所有存储的数据
    const allStoredData = {};

    // 遍历所有键,并获取对应的值
    allKeys.forEach(key => {
        const value = GM_getValue(key);
        allStoredData[key] = value;
    });

    // 构建展示消息
    let message = '';
    Object.entries(allStoredData).forEach(([key, value]) => {
        if (value.title !== undefined) message += `${value.title} (${key}):${value.password}\n•┈┈┈┈┈┈┈┈┈┈┈┈•\n`;
    });

    // 显示消息
    alert(message);
});

// 使用GM_registerMenuCommand添加管理密码的菜单命令
GM_registerMenuCommand('🔒管理密码', function() {
    // 获取所有存储的键值对
    const allStoredData = {};
    const allKeys = GM_listValues();
    allKeys.forEach(key => {
        const value = GM_getValue(key);
        allStoredData[key] = value;
    });

    // 构建展示消息
    let message = '';
    Object.entries(allStoredData).forEach(([key, value]) => {
        if (value.title !== undefined) message += `${value.title} (${key}):${value.password}`;
        if (typeof(window.mbrowser) == "object") message += '$';
        else message += '\n';
    });

    // 提示用户编辑密码列表
    let tip = '换行';
    if (typeof(window.mbrowser) == "object") tip = '$';
    const editedList = prompt('多条密码请使用\'' + tip + '\'分割', message);

    if (editedList !== null) {
        // 清空所有存储的密码
        allKeys.forEach(key => {
            GM_deleteValue(key);
        });

        // 将编辑后的列表转换为标准格式并存储
        let editedLines;
        if (typeof(window.mbrowser) == "object") editedLines = editedList.split('$');
        else editedLines = editedList.split('\n');
        const linePattern = /\((.*?)\)/;
        editedLines.forEach(line => {
            const urlMatch = line.match(linePattern);
            if (urlMatch) {
                const title = line.substring(0, urlMatch.index).trim();
                const url = urlMatch[1].trim();
                const password = line.substring(line.indexOf(':') + 1).trim();
                GM_setValue(url, {
                    title, password
                });
            }
        });

        Toast('密码列表已更新!');
    }
});

// 获取文本框元素
const inputElement = document.getElementById('pwd');

// 获取按钮元素
const subButton = document.getElementById('sub');
const passwddivButton = document.querySelector('.passwddiv-btn');

// 获取存储的值
const storedCredentials = GM_getValue(currentUrl);

// 检查是否存在存储的值
if (storedCredentials) {
    // 如果有存储的数据,将其填充到文本框中
    inputElement.value = storedCredentials.password;

    // 检查是否存在.passwddiv-btn元素
    if (passwddivButton) {
        // 如果存在,点击.passwddiv-btn
        passwddivButton.click();
    } else {
        // 否则点击sub
        subButton.click();
    }
}

const divnoneButton = document.getElementById('divnone');
if (divnoneButton && !currentUrl.includes("/tp/")) {
    const modifiedUrl = currentUrl.replace("com/", "com/tp/");
    window.location.href = modifiedUrl;
}

const submitButton = document.getElementById('submit');
if (submitButton && inputElement) {
    submitButton.click();
    if (storedCredentials) {
        inputElement.value = storedCredentials.password;
    }
    if (passwddivButton) {
        passwddivButton.click();
    } else {
        subButton.click();
    }
}

// 监听文本框的输入事件
inputElement.addEventListener('input', function() {
    // 获取当前网页标题
    const pageTitle = document.title;

    const mdText = document.getElementById('.md');
    if (mdText) pageTitle = mdText.textContent;

    if (pageTitle === '文件') Toast('\"🔒管理密码\"可更改文件名称');
    // 将标题和密码存储为对象
    const credentials = {
        title: pageTitle,
        password: inputElement.value
    };

    // 将对象存储在GM存储中
    GM_setValue(currentUrl, credentials);

});