Last active
October 2, 2021 19:32
-
-
Save Wingysam/4e4279cfcd00e14d918c1f8d9f5c74c4 to your computer and use it in GitHub Desktop.
HN Portal
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name HN Portal | |
// @namespace https://wingysam.xyz | |
// @version 0.3 | |
// @description Use <portal> on HN | |
// @author Wingysam | |
// @match https://news.ycombinator.com/item* | |
// @grant none | |
// ==/UserScript== | |
// USE AN EXTENSION TO DISABLE CSP ON NEWS.YCOMBINATOR.COM OR THIS SCRIPT WON'T WORK. | |
// THIS ONE SHOULD WORK IF YOU CONFIGURE IT CORRECTLY AND USER CHROME. | |
// https://chrome.google.com/webstore/detail/content-security-policy-o/lhieoncdgamiiogcllfmboilhgoknmpi | |
// IF YOU ARE USING A VERSION OF CHROME FROM DECEMBER 2019, GO TO CHROME://FLAGS AND ENABLE PORTALS. | |
// THIS SCRIPT DOES NOT WORK IN FIREFOX AS OF DECEMBER 2019. | |
(function() { | |
'use strict'; | |
const link = document.querySelector('.storylink').href | |
if (window.location.href === link) return | |
document.querySelector('#pagespace').style.display = 'none' | |
const portal = document.createElement('portal') | |
portal.src = link | |
portal.style.width = '100%' | |
portal.style.height = '100%' | |
portal.addEventListener('click', () => { window.location.href = portal.src }) // portal.activate() clears navigation history unfortunately | |
const div = document.createElement('div') | |
div.style.width = '100%' | |
div.style.height = '20em' | |
div.style.boxSizing = 'border-box' | |
div.style.border = '2px solid black' | |
document.querySelector('.fatitem').parentElement.prepend(div) | |
div.appendChild(portal) | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment