Skip to content

Commit

Permalink
Check we're on a mastodon instance before adding translate options
Browse files Browse the repository at this point in the history
  • Loading branch information
tomouchuu committed Aug 27, 2018
1 parent d42b200 commit b1089be
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions index.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name MastodonTranslate
// @namespace https://niu.moe/@tomo
// @version 1.7.5
// @version 1.8.0
// @description Provides a translate toot option for Mastodon users via GoogleTranslate
// @author [email protected] / https://niu.moe/@tomo
// @match *://*/web/*
Expand Down Expand Up @@ -128,13 +128,27 @@
);
}

document.querySelector('body').addEventListener('click', function(event) {
if (chromeClickChecker(event) || firefoxClickChecker(event)) {
// Get the status for this event
var status = event.target.parentNode.parentNode.parentNode.parentNode.parentNode;
addTranslateLink(status);
function activateMastodonTranslate() {
document.querySelector('body').addEventListener('click', function(event) {
if (chromeClickChecker(event) || firefoxClickChecker(event)) {
// Get the status for this event
var status = event.target.parentNode.parentNode.parentNode.parentNode.parentNode;
addTranslateLink(status);
}
}, false);
}

// Launch Script
setTimeout(function() {
// Checks we're on a mastodon instance
var settingsEl = document.querySelector('a.drawer__tab[title="Preferences"]');
var settingsUrl = settingsEl.getAttribute('href');
if (settingsUrl === '/settings/preferences') {
activateMastodonTranslate();
} else {
// Probably on the mastofe of pleroma or something
}
}, false);
}, 100);

if (window.location.pathname === '/settings/preferences') {
// We're on the settings page
Expand Down

0 comments on commit b1089be

Please sign in to comment.