Skip to content

Commit

Permalink
[new feature] adapt zhihu.com/tardis page
Browse files Browse the repository at this point in the history
  • Loading branch information
ATX735 committed May 21, 2023
1 parent c5f1a18 commit f82d7bb
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 10 deletions.
Binary file removed demo pictures/1.png
Binary file not shown.
File renamed without changes
Binary file added demo/MSShop_img_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
22 changes: 20 additions & 2 deletions src/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,36 @@ chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
switch (message.type) {
// 打开/刷新页面时
case "content js-initial_css_injection":
chrome.scripting.insertCSS({ //注入含有变量的css
//注入含有变量的css
chrome.scripting.insertCSS({
target: {
tabId: sender.tab.id,
},
css: getVariableCSS(current_style)
});
chrome.scripting.insertCSS({ //注入固定css
//注入固定css
chrome.scripting.insertCSS({
target: {
tabId: sender.tab.id,
},
files: ["new-zhihu-style.css"]
});
//处理存在冲突的css
let reg = /zhihu.com\/tardis\/*/ //匹配知乎的zhihu.com/tardis/*页面
let confilct_css = `.Question-main {
width: var(--width-container) !important;
}`
if (reg.test(sender.tab.url)) {
confilct_css = `.Question-main {
width: var(--width-main-column) !important;
}`
}
chrome.scripting.insertCSS({
target: {
tabId: sender.tab.id,
},
css: confilct_css
});
break;
// popup页面被打开时
case "popup js-initialize":
Expand Down
4 changes: 2 additions & 2 deletions src/manifest.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "宽乎",
"version": "1.0.3",
"version": "1.1.0",
"manifest_version": 3,
"description": "加宽知乎各个页面的内容区域,优化浏览体验。",
"description": "加宽知乎各页面的内容区域,优化浏览体验。",
"icons": {
"16": "icons/logo.png",
"48": "icons/logo.png",
Expand Down
24 changes: 18 additions & 6 deletions src/new-zhihu-style.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,11 @@
width: var(--width-main-column) !important;
}

/*.Modal--fullPage{*/
/* width: var(--width-container);*/
/*}*/


/*问题页面*/
.Question-main {
/* .Question-main { // 存在冲突的CSS
width: var(--width-container) !important;
}
} */

.Question-mainColumn {
width: var(--width-main-column) !important;
Expand Down Expand Up @@ -114,4 +110,20 @@

.AuthorInfo {
max-width: var(--width-main-column) !important;
}

/* 文章编辑页面 */
/* .css-sdgtgb {
width: var(--width-main-column) !important;
} */


/* 未登录的知乎文章页面,往往会在搜索引擎结果中打开这种页面 */
/* Example:https://www.zhihu.com/tardis/zm/ans/2890071661 */
.sgui-radius-flex {
max-width: var(--width-main-column) !important;
}

.Container {
max-width: var(--width-main-column) !important;
}

0 comments on commit f82d7bb

Please # to comment.