term.ptt autologin

restore term.ptt autologin function

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         term.ptt autologin
// @namespace    NoNameSpace
// @version      0.3
// @description  restore term.ptt autologin function
// @match        *://term.ptt.cc
// @match        *://term.ptt.cc/*
// @grant        none
// @run-at       document-start
// ==/UserScript==

var RealWebSocket = window.WebSocket;
class FakeWebSocket extends RealWebSocket {
    constructor(url) {
        super(url);
        this.sendStr = (e) => {
            for (var t = 0; t < e.length; t += 1e3) {
                var i = e.substring(t, t + 1e3)
                , s = new Uint8Array(i.split("").map(function(e) {
                    return e.charCodeAt(0);
                }));
                this.send(s.buffer);
            }
        };
        this.addEventListener("open", () => {
            setTimeout(() => {
                var USER = '';
                var PASS = '';
                this.sendStr(USER + '\x0d' + PASS + '\x0d');
            }, 500);
        });
    }
}
window.WebSocket = FakeWebSocket;

var ael = window.addEventListener;
window.addEventListener = function (...args) {
    if (args[0] === 'beforeunload') return;
    return ael.apply(this, args);
};