Created
July 24, 2023 19:08
-
-
Save b3e3e3/3a677e72747cdeb85bb6f7575235a0cb to your computer and use it in GitHub Desktop.
Redirect from Twitter to Bluesky userscript
This file contains 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 Twitter Redirect Prompt | |
// @namespace http://tampermonkey.net/ | |
// @version 0.7 | |
// @description Adds a non-intrusive modal on Twitter homepage to redirect to bsky.app | |
// @author @dynastic on twitter, @dynastic.xyz on bsky | |
// @match https://twitter.com/* | |
// @grant none | |
// ==/UserScript== | |
(function() { | |
'use strict'; | |
let count = 7; | |
function countdown() { | |
if (count > 1) { | |
count -= 1; | |
document.getElementById('counter') | |
.innerHTML = `${count}` | |
setTimeout(countdown, 1000) | |
} | |
else { | |
removeMessageElement(); | |
} | |
} | |
setTimeout(countdown, 1000); | |
const messageElement = document.createElement('div'); | |
messageElement.id = 'twitterRedirectPrompt'; | |
messageElement.innerHTML = ` | |
<div style="position: fixed; top: 20px; left: 20px; align-items: center; background-color: #000; padding: 10px; border: 1px solid #fff; border-radius: 10px; box-shadow: 0 0 7px #fff; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;"> | |
<div> | |
<p style="color: #fff; font-weight: 800; font-size: 20px;">Would you like to redirect to <a href="https://bsky.app/" target="_blank" style="color: #fff; text-decoration: underline;">https://bsky.app/</a> instead?</p> | |
</div> | |
<div style="display: flex; align-items: center;"> | |
<button style="background-color: #1A8CD8; color: #fff; border: none; padding: 8px 15px; margin-right: 5px; border-radius: 100px; cursor: pointer; font-weight: bold;" id="redirectButton">Redirect</button> | |
<button style="background-color: #1A8CD8; color: #fff; border: none; padding: 8px 15px; margin-right: 5px; border-radius: 100px; cursor: pointer; font-weight: bold;" id="closeButton">Close</button> | |
<p style="color: #fff; margin-right: 10px; font-style: italic;"><small>Closing in <span id="counter">${count}</span></small></p> | |
</div> | |
</div> | |
`; | |
document.body.appendChild(messageElement); | |
const removeMessageElement = () => { | |
const elementToRemove = document.getElementById('twitterRedirectPrompt'); | |
if (elementToRemove) { | |
elementToRemove.remove(); | |
} | |
}; | |
const handleRedirectButtonClick = () => { | |
window.location.href = 'https://bsky.app/'; | |
}; | |
const handleCloseButtonClick = () => { | |
removeMessageElement(); | |
}; | |
const closeButton = document.getElementById('closeButton'); | |
if (closeButton) { | |
closeButton.addEventListener('click', handleCloseButtonClick); | |
} | |
const redirectButton = document.getElementById('redirectButton'); | |
if (redirectButton) { | |
redirectButton.addEventListener('click', handleRedirectButtonClick); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment