|
1 | 1 | // ==UserScript== |
2 | 2 | // @name V2EX 增强 |
3 | | -// @version 1.2.0 |
| 3 | +// @version 1.2.1 |
4 | 4 | // @author X.I.U |
5 | 5 | // @description 自动签到、链接转图片、自动无缝翻页、使用 SOV2EX 搜索、回到顶部(右键点击两侧空白处)、快速回复(左键双击两侧空白处)、新标签页打开链接、标签页伪装为 Github(摸鱼) |
6 | 6 | // @match *://v2ex.com/* |
|
85 | 85 | SiteTypeID: 1, |
86 | 86 | pager: { |
87 | 87 | type: 1, |
88 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
| 88 | + nextLink: 'css;.page_current+a', |
89 | 89 | pageElement: 'css;.cell.item', |
90 | | - HT_insert: ['//div[@id="Main"]//div[@class="box"]//div[@class="cell"][last()]', 1], |
91 | | - replaceE: 'css;#Main > .box > .cell[style]:not(.item) > table', |
| 90 | + HT_insert: ['css;.cell.ps_container:last-of-type', 1], |
| 91 | + replaceE: '//a[@class="page_current"]/../..', |
92 | 92 | scrollDelta: 1500 |
93 | 93 | } |
94 | 94 | }, |
95 | 95 | notifications: { // 提醒消息页 |
96 | 96 | SiteTypeID: 2, |
97 | 97 | pager: { |
98 | 98 | type: 1, |
99 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
| 99 | + nextLink: 'css;.page_current+a', |
100 | 100 | pageElement: 'css;#notifications > div', |
101 | 101 | HT_insert: ['css;#notifications', 3], |
102 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 102 | + replaceE: '//a[@class="page_current"]/../..', |
103 | 103 | scrollDelta: 1500 |
104 | 104 | } |
105 | 105 | }, |
106 | 106 | replies: { // 用户回复页 |
107 | 107 | SiteTypeID: 3, |
108 | 108 | pager: { |
109 | 109 | type: 1, |
110 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
111 | | - pageElement: '//div[@id="Main"]//div[@class="box"]//div[@class="dock_area"] | //*[@id="Main"]//div[@class="box"]//div[@class="inner"] | //*[@id="Main"]//div[@class="box"]//div[@class="dock_area"][last()]/following-sibling::div[@class="cell"][1]', |
112 | | - HT_insert: ['//div[@id="Main"]//div[@class="box"]//div[@class="cell"][last()]', 1], |
113 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 110 | + nextLink: 'css;.page_current+a', |
| 111 | + pageElement: 'css;#Main>.box>.dock_area,#Main>.box>.dock_area+.inner,#Main>.box>.dock_area+.cell:not([style])', |
| 112 | + HT_insert: ['css;.cell.ps_container:last-of-type', 1], |
| 113 | + replaceE: '//a[@class="page_current"]/../..', |
114 | 114 | scrollDelta: 1500 |
115 | 115 | } |
116 | 116 | }, |
117 | 117 | go: { // 分类主题页 |
118 | 118 | SiteTypeID: 4, |
119 | 119 | pager: { |
120 | 120 | type: 1, |
121 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
| 121 | + nextLink: 'css;.page_current+a', |
122 | 122 | pageElement: 'css;#TopicsNode > div', |
123 | 123 | HT_insert: ['css;#TopicsNode', 3], |
124 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 124 | + replaceE: '//a[@class="page_current"]/../..', |
125 | 125 | scrollDelta: 1500 |
126 | 126 | } |
127 | 127 | }, |
128 | 128 | reply: { // 帖子内容页(从前往后) |
129 | 129 | SiteTypeID: 5, |
130 | 130 | pager: { |
131 | 131 | type: 1, |
132 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
| 132 | + nextLink: 'css;.page_current+a', |
133 | 133 | pageElement: 'css;.cell[id^="r_"]', |
134 | | - HT_insert: ['//div[starts-with(@id, "r_")][last()]/following-sibling::div[@class="cell"][1]', 1], |
135 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 134 | + HT_insert: ['css;.cell.ps_container:last-of-type', 1], |
| 135 | + replaceE: '//a[@class="page_current"]/../..', |
136 | 136 | scrollDelta: 1500 |
137 | 137 | } |
138 | 138 | }, |
139 | 139 | reply_positive: { // 帖子内容页(从后往前) |
140 | 140 | SiteTypeID: 6, |
141 | 141 | pager: { |
142 | 142 | type: 1, |
143 | | - nextLink: '//a[@class="page_current"]/preceding-sibling::a[1][@href]', |
| 143 | + nextLink: 'css;.page_current+a', |
144 | 144 | pageElement: 'css;.cell[id^="r_"]', |
145 | | - HT_insert: ['//div[starts-with(@id, "r_")][1]', 1], |
146 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 145 | + HT_insert: ['css;.cell[id^="r_"]', 1], |
| 146 | + replaceE: '//a[@class="page_current"]/../..', |
147 | 147 | scrollDelta: 1500 |
148 | 148 | } |
149 | 149 | }, |
150 | 150 | balance: { // 账户余额页 |
151 | 151 | SiteTypeID: 7, |
152 | 152 | pager: { |
153 | 153 | type: 1, |
154 | | - nextLink: '//a[@class="page_current"]/following-sibling::a[1][@href]', |
155 | | - pageElement: 'css;#Main .box > div:not(.cell) > table > tbody > tr:not(:first-child)', |
156 | | - HT_insert: ['css;#Main .box > div:not(.cell) > table > tbody', 3], |
157 | | - replaceE: 'css;#Main > .box > .cell[style] > table', |
| 154 | + nextLink: 'css;.page_current+a', |
| 155 | + pageElement: 'css;table.data>tbody>tr:not(:first-child)', |
| 156 | + HT_insert: ['css;table.data>tbody', 3], |
| 157 | + replaceE: '//a[@class="page_current"]/../..', |
158 | 158 | scrollDelta: 1000 |
159 | 159 | } |
160 | 160 | }, |
|
470 | 470 | }, |
471 | 471 | loadMorePage: function () { |
472 | 472 | if (curSite.pager) { |
473 | | - let curPageEle = getElementByXpath(curSite.pager.nextLink); |
| 473 | + let curPageEle = getOneElements(curSite.pager.nextLink); |
474 | 474 | var url = this.getFullHref(curPageEle); |
475 | 475 | console.log(`${url} ${curPageEle} ${curSite.pageUrl}`); |
476 | 476 | if(url === '') return; |
|
576 | 576 | } |
577 | 577 | return result; |
578 | 578 | } |
| 579 | + function getOneElements(selector, contextNode = undefined, doc = document) { |
| 580 | + if (!selector) return; |
| 581 | + contextNode = contextNode || doc; |
| 582 | + if (selector.search(/^css;/i) === 0) { |
| 583 | + return getElementByCSS(selector.slice(4), contextNode); |
| 584 | + } else { |
| 585 | + return getElementByXpath(selector, contextNode, doc); |
| 586 | + } |
| 587 | + } |
579 | 588 | function getAllElements(selector, contextNode = undefined, doc = document, win = window, _cplink = undefined) { |
580 | 589 | if (!selector) return []; |
581 | 590 | contextNode = contextNode || doc; |
|
0 commit comments