跳转到内容

User:Chubit/vector-max-width-toggle.js

维基百科,自由的百科全书

这是User:Chubit/vector-max-width-toggle.js当前版本,由Chubit留言 | 贡献编辑于2021年8月3日 (二) 07:02。这个网址是本页该版本的固定链接。

(差异) ←上一修订 | 最后版本 (差异) | 下一修订→ (差异)
注意:保存之后,你必须清除浏览器缓存才能看到做出的更改。Google ChromeFirefoxMicrosoft EdgeSafari:按住⇧ Shift键并单击工具栏的“刷新”按钮。参阅Help:绕过浏览器缓存以获取更多帮助。
/**
 * Usage instructions: mw.loader.getScript('https://zh.wikipedia.org/w/index.php?title=User:Chubit/vector-max-width-toggle.js&action=raw&ctype=text/javascript');
 */
$(function(){
var lastValue;
try {
    lastValue = localStorage.getItem('max-width-on') || '0';
} catch (e) {
    lastValue = '0';
}

if (lastValue === '1') {
    $(document.body).toggleClass('skin-vector-max-width');
}


var originalMaxWidth = $('.mw-content-container').css('max-width')

var $switcher = $('<div style="position:absolute;right:0;top:0;background-image: url(/media/wikipedia/commons/2/28/Font_Awesome_5_solid_window-maximize.svg);width: 40px;height: 40px;background-size: 20px;background-position: top right;background-repeat: no-repeat;"></div>')
    .on('click', function() {
        $(document.body).toggleClass('skin-vector-max-width');
        localStorage.setItem('max-width-on', lastValue === '0' ? '1' : '0');
        var currentMaxWidth = $('.mw-content-container').css('max-width')
        $('.mw-content-container').css('max-width', currentMaxWidth === 'none' ? originalMaxWidth : 'none')
    } ).prependTo('#content');

$('#content').css('position', 'relative')
});