1. 程式人生 > >幾個小指令碼

幾個小指令碼

隨便翻一下谷歌瀏覽器除錯工具(F12)執行過的指令碼,摘幾個貼一下。

原文連結:http://www.markjour.com/article/20181205-scripts.html
隨意轉載,留個上面這個連結即可,哈哈。

Gitee GVP

匯出 GVP 專案列表,做個參考。

var jqEleProjects = $('#gvp-index-segment > div.ui.four.cards.all-projects > div > div.content.description-content');
var projects = {};
var languages = {};
var types = {};
jqEleProjects.each(function(){
    var name = $(this).find('h3 > a').text();
    var url = $(this).find('h3 > a').attr('href');
    var type = $(this).find('div > div > div:nth-child(1)').text();
    var language = $(this).find('div > div > div:nth-child(2)').text();
    projects[name] = {name: name, url: url, type: type, language: language};
    if (!languages.hasOwnProperty(language)) { languages[language] = []; }
    languages[language].push(name);
    if (!types.hasOwnProperty(type)) { types[type] = []; }
    types[type].push(name);
    // console.log(name + ' - ' + type + ' - ' + language + ' - ' + url);
});
console.log(projects);
console.log(languages);
console.log(types);

API 測試時先調登入介面

xhr = new XMLHttpRequest();
xhr.open('post', 'http://localhost:9996/login', true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send('username=catroll&password=123456');

heidiSQL 找回資料庫密碼

get database password from heidisql settings file

有個配置檔案,就在 heidisql 安裝目錄下,叫 settings.txt,自己找找。

function heidiDecode(hex) {
    var str = '';
    var shift = parseInt(hex.substr(-1));
    hex = hex.substr(0, hex.length - 1);
    for (var i = 0; i < hex.length; i += 2)
      str += String.fromCharCode(parseInt(hex.substr(i, 2), 16) - shift);
    return str;
}

Python 版本:

from __future__ import print_function

import re
import codecs

HEIDI_CONF = '/media/sf_D_DRIVE/Program Files/HeidiSQL/settings.txt'
HEIDI_CONF_SEP = re.compile(re.escape('<|||>'))


def heidi_pw_decode(code):
    shift = int(code[-1])
    code = code[:-1]
    password = ''.join(map(lambda x: chr(int(x, 16) - shift), re.findall(r'\w{2}', code)))
    return password


def main():
    with codecs.open(HEIDI_CONF, encoding="utf8") as fp:
        lines = [line.strip() for line in fp.readlines()
                 if line.startswith('Servers') and '\\Password<' in line]

    passwords = []
    for line in lines:
        parts = HEIDI_CONF_SEP.split(line)
        server_name = parts[0].split('\\')[1]
        password = heidi_pw_decode(parts[-1])
        passwords.append((server_name, password))

    if passwords:
        print(' All Database Passwords '.center(80, '-'))
        print()
        for server_name, password in passwords:
            print('Database: %s' % server_name)
            print('Password: %s' % password)
            print()
    else:
        print('[INFO] No password can be found!')


if __name__ == '__main__':
    main()

列出 Python 文件中的章節

我當時好像是為了比對 2 和 3 的文件章節差異,看看 3 多了些什麼...

var chapters = {};
var arrL1 = $('.toctree-l1 > a');
var arrL2 = $('.toctree-l2 > a');
var content = '';
$('.toctree-l1').each(function() {
    var l1Title = $(this).find(arrL1).text();
    content += '- ' + l1Title + '\n';
    chapters[l1Title] = [];
    $(this).find(arrL2).each(function() {
        var l2Title = $(this).html();
        l2Title = l2Title.replace(/<code class="docutils literal notranslate"><span class="pre">|<\/span><\/code>/g, '`');
        l2Title = l2Title.replace(/<strong class="program">|<\/strong>/g, '**');
        chapters[l1Title].push(l2Title);
        content += '  - ' + l2Title + '\n';
    });
});
// console.log(JSON.stringify(chapters));
console.log(content);

自動刪除網易郵箱的郵件

有些資料夾下的郵件實在太多,好幾千封,兩百大幾十頁,要是一個一個的全選、刪除、等執行完成,那不累死,不是程式設計師該做的事。
寫了個指令碼,自動勾選刪除。

PS:指令碼沒有找到,等找到了再補上。