1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 06:40:32 +05:30
yattee/Open in Yattee/content.js
2021-11-07 17:52:42 +01:00

27 lines
679 B
JavaScript

if (document.readyState !== 'complete') {
window.addEventListener('load', redirectAndReplaceContentWithLink);
} else {
redirectAndReplaceContentWithLink();
}
function yatteeUrl() {
return window.location.href.replace(/^https?:\/\//, 'yattee://');
}
function yatteeLink() {
return '<a href="'+ yatteeUrl() +'" onclick=\'window.location.href="'+ yatteeUrl() +'"\'>Open in Yattee</a>';
}
function redirect() {
window.location.href = yatteeUrl()
}
function replaceContentWithLink() {
document.querySelector('body').innerHTML = '<h1>' + yatteeLink() + '</h1>';
}
function redirectAndReplaceContentWithLink(){
redirect()
replaceContentWithLink()
}