Toggle InstantMarkdown width

Adds a button to toggle between full width and GitHub default width

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Toggle InstantMarkdown width
// @description  Adds a button to toggle between full width and GitHub default width
// @match        http://localhost:8090/
// @grant        none
// @namespace    http://foo.at/
// @version      1.0
// ==/UserScript==

/*
 * Copyright 2015-2016 Stefan Weiss <[email protected]>
 * License: Public Domain
 * Please let me know if this script stops working for you.
 */

/* jshint esversion: 6 */
(function () {

    "use strict";

    if (!_qs("#js-repo-pjax-container")) {
        return;
    }

    let toggled = false;
    const btn = document.createElement("button");
    btn.textContent = "Toggle width";
    btn.style.cssText = "position: absolute; top: 10px; right: 10px";
    document.body.appendChild(btn);

    btn.onclick = function () {
        _qs(".container").style.width = toggled ? "980px" : "auto";
        _qs("#js-repo-pjax-container").style.width = toggled ? "790px" : "auto";
        _qs("article.markdown-body").style.maxWidth = toggled ? "790px" : "100%";
        toggled = !toggled;
    };

    function _qs (sel, base)
    {
        return (base || document).querySelector(sel);
    }

})();