您需要先安装一个扩展,例如 篡改猴、Greasemonkey 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 暴力猴,之后才能安装此脚本。
您需要先安装一个扩展,例如 篡改猴 或 Userscripts ,之后才能安装此脚本。
您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。
您需要先安装用户脚本管理器扩展后才能安装此脚本。
Display post "Insight" inline instead of in another page
当前为
- // ==UserScript==
- // @name Reddit - Inline post insight
- // @namespace https://github.com/Procyon-b
- // @version 0.5.1
- // @description Display post "Insight" inline instead of in another page
- // @author Achernar
- // @match https://www.reddit.com/*
- // @match https://sh.reddit.com/*
- // @grant none
- // @run-at document-start
- // ==/UserScript==
- (function() {
- "use strict";
- var started=0;
- function start() {
- if (started++) return;
- document.body.addEventListener('click', function(ev){
- console.info({ev});
- var t=ev.target, r, f;
- if (t.href && (location.hostname == t.hostname) && t.pathname.startsWith('/poststats/') ) {
- ev.stopPropagation();
- ev.preventDefault();
- r=t.closest('div');
- r.outerHTML='<iframe src="'+t.pathname+'" id="poststats" style="border: none; height: 0;"></iframe>';
- }
- }, true);
- }
- function addStyle() {
- if (location.pathname.startsWith('/poststats/')) {
- let st=document.createElement("style");
- document.documentElement.appendChild(st);
- st.textContent=
- `html, * , :host * {
- background: transparent !important;
- background-color: transparent !important;
- }
- body > :not(shreddit-app),
- shreddit-app > :not([rpl]),
- shreddit-app > [rpl]::before,
- shreddit-app > [rpl] > :not(#subgrid-container),
- .main-container > :not(main),
- main > div > div,
- main > div > div + section
- {
- display: none !important;
- }
- shreddit-app > [rpl] {
- display: block !important;
- }
- obody,
- shreddit-app,
- shreddit-app > [rpl],
- #subgrid-container,
- #subgrid-container > .main-container,
- #subgrid-container > .main-container > main {
- display: contents !important;
- }
- main > div {
- margin: 0 !important;
- padding: 0 !important;
- }
- a {
- pointer-events: none;
- }`;
- }
- }
- function resize() {
- var TO=0, iframe;
- if (!(iframe=parent.document.querySelector('iframe#poststats'))) return;
- function resizeIframe() {
- if (TO) {clearTimeout(TO); TO=0;}
- iframe.style.height=document.body.scrollHeight + 20 + 'px';
- }
- const obs = new ResizeObserver(function(e){
- if (TO) {clearTimeout(TO);}
- TO=setTimeout(resizeIframe,200);
- });
- obs.observe(document.body);
- }
- function tryUntil(F, TO=150, c=-1, fail) {
- if (!c--) {
- fail && fail();
- return;
- }
- try{F();}catch(e){setTimeout(function(){tryUntil(F,TO,c,fail);}, TO)}
- }
- if (window === window.top) {
- if (document.readyState != 'loading') start();
- else {
- document.addEventListener('DOMContentLoaded', start);
- window.addEventListener('load', start);
- }
- }
- else {
- tryUntil(addStyle ,0);
- tryUntil(resize, 0);
- }
- })();