// ==UserScript== // @name Jike Enhanced // @namespace https://web.okjike.com/ // @version 0.3 // @description 即刻网页版增强,支持全局返回和消息跳转,来愉快地刷即刻吧! // @author iMaeGoo // @match https://web.okjike.com/* // @grant GM_addStyle // @grant unsafeWindow // @downloadURL https://update.greasyfork.icu/scripts/419530/Jike%20Enhanced.user.js // @updateURL https://update.greasyfork.icu/scripts/419530/Jike%20Enhanced.meta.js // ==/UserScript== (function () { 'use strict'; // 添加返回 btn function addBackBth () { const backEl = document.createElement('a') backEl.classList.add('gm-back-btn') // backEl.innerText = '<' backEl.innerHTML = '' backEl.onclick = () => { history.back() } document.body.appendChild(backEl) } // 拦截请求 function interceptRequest () { const originFetch = fetch unsafeWindow.fetch = async (url, request) => { const response = await originFetch(url, request) if (url === 'https://web-api.okjike.com/api/graphql') { // 拦截处理即刻 API try { const text = await response.text() response.text = () => { return new Promise((resolve) => { resolve(text) }) } const req = JSON.parse(request.body) const res = JSON.parse(text) if (req.operationName === 'ListNotification') { setTimeout(() => { addNotificationLink(res) }, 200) } } catch (e) { console.error(e) } } return response } } // 添加通知链接 function addNotificationLink (res) { const nodes = res.data.viewer.notifications.nodes const notificationsEl = document.querySelectorAll('[class^="Notification__NotiItemContainer"]') const startIndex = notificationsEl.length - nodes.length let index = -1 for (const node of nodes) { index++ if (node.referenceItem && node.linkUrl) { let url if (node.linkType === 'COMMENT') { const postId = node.linkUrl.substr(node.linkUrl.indexOf('targetId=') + 'targetId='.length, 24) url = `https://web.okjike.com/originalPost/${postId}` } else { url = node.linkUrl.replace('jike://page.jk', 'https://web.okjike.com') } const elem = notificationsEl[startIndex + index] if (elem) { elem.onclick = () => { location.href = url } elem.style.cursor = 'pointer' } } } } GM_addStyle(` .gm-back-btn { position: fixed; z-index: 101; top: 0; left: 0; width: 32px; height: 32px; border-radius: 16px; margin: 12px; display: flex; align-items: center; justify-content: center; font-weight: bold; color: rgb(153, 153, 153); background-color: rgb(242, 245, 248); cursor: pointer; } .cDyYuq { width:300px !important; } .iFOUyg { flex: none !important; } .EdRZd { padding: 0px 48px !important; `) addBackBth() interceptRequest() })()