-
Notifications
You must be signed in to change notification settings - Fork 327
/
zhihu_mobile_fuck.user.js
141 lines (132 loc) · 5.8 KB
/
zhihu_mobile_fuck.user.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ==UserScript==
// @name Fuck ZhiHu Mobile
// @namespace https://github.com/ipcjs
// @version 2.0.2
// @description 日他娘的逼乎手机网页版; 针对手机版进行修改,把所有的“App 内查看”按钮屏蔽了;
// @author ipcjs
// @include https://www.zhihu.com/*
// @include https://zhuanlan.zhihu.com/*
// @grant GM_addStyle
// @require https://greasyfork.org/scripts/373283-ipcjs-lib-js/code/ipcjslibjs.js?version=647820
// ==/UserScript==
ipcjs.installInto(({ log, html, $ }) => {
log = GM_info.script.name.endsWith('.dev') ? log : () => { }
GM_addStyle(`
.DownloadGuide {
display: none;
}
.OpenInAppButton {
display: none;
}
.MobileAppHeader-downloadLink {
display: none;
}
/*
button.ContentItem-more {
position: absolute;
}
*/
`)
installToContent(document)
new MutationObserver((mutations, observer) => {
// log(mutations)
for (let m of mutations) {
const $target = $(m.target)
for (let node of m.addedNodes) {
if (node.nodeType === Node.ELEMENT_NODE) {
if ($(node).hasClass('RichContent-inner')
&& $target.hasClass('RichContent') && $target.hasClass('is-collapsed')) {
log('contentInner added, need reinstall', node)
installToContent($target.ele.parentElement)
} else {
installToContent(node)
}
}
}
}
}).observe(document.body, {
childList: true,
subtree: true
})
function installToContent(node) {
if (!node.querySelectorAll) {
return
}
const contentItems = node.querySelectorAll('.RichContent')
const collapseButtonHtml = '<button data-zop-retract-question="true" type="button" class="Button ContentItem-action ContentItem-rightButton Button--plain"><span class="RichContent-collapsedText">收起</span><span style="display: inline-flex; align-items: center;"><svg class="Zi Zi--ArrowDown ContentItem-arrowIcon is-active" fill="currentColor" viewBox="0 0 24 24" width="24" height="24"><path d="M12 13L8.285 9.218a.758.758 0 0 0-1.064 0 .738.738 0 0 0 0 1.052l4.249 4.512a.758.758 0 0 0 1.064 0l4.246-4.512a.738.738 0 0 0 0-1.052.757.757 0 0 0-1.063 0L12.002 13z" fill-rule="evenodd"></path></svg></span></button>'
if (contentItems.length > 0) {
log('install', contentItems)
}
contentItems.forEach((content, index) => {
const contentInner = content.querySelector('.RichContent-inner')
const actions = content.querySelector('.ContentItem-actions')
const expandButtonOuter = content.querySelector(':scope > button')
const expandButtonInner = contentInner.querySelector(':scope > button')
const $content = $(content)
let diff = {
expandButton: undefined,
expandButtonText: undefined,
onClick: undefined,
onEach: undefined,
}
if (expandButtonOuter) {
diff = {
expandButton: expandButtonOuter,
expandButtonText: '展开阅读全文',
onClick: function toggleContent() {
let collapseButton = actions.querySelector('button.Button.ContentItem-rightButton')
if ($content.hasClass('is-collapsed')) {
$content.removeClass('is-collapsed')
contentInner.style.maxHeight = ''
diff.expandButton.style.display = 'none'
collapseButton = html(collapseButtonHtml)[0]
collapseButton.addEventListener('click', toggleContent)
actions.appendChild(collapseButton)
} else {
$content.addClass('is-collapsed')
contentInner.style.maxHeight = '400px'
diff.expandButton.style.display = 'inline'
actions.removeChild(collapseButton)
}
},
onEach: () => { }
}
} else if (expandButtonInner) {
const contentCover = content.querySelector('.RichContent-cover')
diff = {
expandButton: expandButtonInner,
expandButtonText: contentCover ? '展开' : '跳转',
onClick: function gotoDetail() {
if (contentCover) {
contentCover.click()
} else {
const urlMeta = content.parentElement.querySelector(':scope > meta[itemprop=url]')
location.href = urlMeta.content
}
},
onEach: function () {
$content.removeClass('is-collapsed')
}
}
} else {
log('expandButton no found')
return
}
diff.onEach()
if (diff.expandButton.innerText.startsWith('App 内查看')) {
diff.expandButton.innerText = diff.expandButtonText
diff.expandButton.addEventListener('click', e => {
e.stopPropagation()
diff.onClick()
}, true)
} else {
log('skip', content)
return
}
contentInner.addEventListener('click', e => {
e.stopPropagation()
diff.onClick()
}, true)
})
}
})