突发奇想,让 chatpgt 写了个 V2EX 内容居中的油猴小工具

332 天前
 YiPeng0505
用笔记本逛 V2EX 的时候老是得稍微扭一下脖子,有那么些许不得劲,于是:

👨‍💻:请写一个油猴脚本,屏蔽 https://www.v2ex.com/ 网站内的<div id = “Rightbar”></div> 里的内容,并且让<div id = “Main”></div> 里的内容居中显示

💻:
// ==UserScript==
// @name Hide V2EX right bar and center main content
// @namespace v2ex-hide-rightbar-center-content
// @description Hide the right bar and center main content on V2EX website.
// @version 1
// @grant none
// @match https://www.v2ex.com/*
// ==/UserScript==

(function() {
'use strict';

// Hide the right bar
var rightBar = document.querySelector('#Rightbar');
if (rightBar) {
rightBar.style.display = 'none';
}

// Center the main content
var mainContent = document.querySelector('#Main');
if (mainContent) {
mainContent.style.margin = '0 auto';
mainContent.style.maxWidth = '1000px'; // Optional: limit the maximum width of center content
}
})();
861 次点击
所在节点    分享发现
2 条回复
autoxbc
332 天前
这届 GPT 不行啊,应该写成 CSS 然后用 GM_addStyle 加载
itlaohui
330 天前
改成 css 是这样?

#Rightbar {
display: none;
}

#Main {
margin: 0 auto;
max-width: 1000px;
}

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/946291

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX