Skip to content

Instantly share code, notes, and snippets.

@happiness801
Last active July 11, 2022 18:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save happiness801/78aaeb3ab9fe0843e26a10f81f83b5da to your computer and use it in GitHub Desktop.
Save happiness801/78aaeb3ab9fe0843e26a10f81f83b5da to your computer and use it in GitHub Desktop.
Show URL at top of App Windows
// ==UserScript==
// @name Show URL at top of App Windows
// @namespace http://onai.net/
// @version 0.5
// @description Shows current URL at top of windows for easy copy and paste in App Windows
// @author Kevin Gwynn
// @match https://*.medium.com/*
// @match https://*.twitter.com/*
// @match https://*.pluralsight.com/*
// @match https://*.facebook.com/*
// @match https://*.linkedin.com/*
// @exclude https://*.linkedin.com/tscp-serving/*
// @match https://*.gartner.com/*
// @match https://*.miro.com/*
// @match https://*.oreilly.com/*
// @match https://*.excalidraw.com/*
// @grant none
// ==/UserScript==
(function() {
'use strict';
let previousUrl = '';
new MutationObserver(function(mutations) {
if (location.href !== previousUrl) {
previousUrl = location.href;
console.log('Navigated to: ' + previousUrl);
let easyUrlInput = document.getElementById('easy-url-input');
easyUrlInput ? easyUrlInput.value = previousUrl : null;
}
}).observe(
document,
{ subtree: true, childList: true }
);
let clearLinkTargets = function() {
console.log('KAG: clear-link-targets.user.js');
let links = document.getElementsByTagName('a');
for (let x = 0; x < links.length; x++) {
if (links[x].target != '') links[x].target = '';
}
};
let showURL = function() {
console.log('KAG: show URL at top...');
var easyUrlContainer = document.createElement('div');
easyUrlContainer.id = 'easy-url';
var url = document.location.href;
var urlPrefix = url.startsWith('https') ? '🔒' : '🔓';
var easyUrlInput = document.createElement('input');
easyUrlInput.type = 'text';
easyUrlInput.id = 'easy-url-input';
easyUrlInput.value = url;
easyUrlContainer.appendChild(easyUrlInput);
document.body.appendChild(easyUrlContainer);
var easyUrlStyle = document.createElement('style');
easyUrlStyle.innerHTML = '\
#easy-url { \
display:block;\
position:fixed;\
overflow:hidden;\
left:5px;\
top:-8px;\
z-index:2147483647;\
font-size:small;\
font-family:sans-serif;\
background-color:#EEE;\
padding:3px 5px;\
border:1px solid black;\
width:27px;\
height:30px;\
opacity:.25;\
transition:all 250ms 20ms;\
white-space:nowrap;\
}\
#easy-url:hover { \
width:95%;\
opacity:1;\
top:-1px;\
}\
#easy-url:before {\
content: "' + urlPrefix + '";\
}\
#easy-url-input {\
width:96%;\
margin-left:5px;\
}\
';
document.head.appendChild(easyUrlStyle);
easyUrlContainer.addEventListener('mouseenter', function(){
easyUrlInput.focus();
easyUrlInput.select();
//document.execCommand('copy');
});
easyUrlInput.addEventListener('keypress', function(event) {
if (event.which == 13) {
window.location = this.value;
}
});
};
setTimeout(showURL, 1000);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment