Skip to content

Commit

Permalink
fix: also dynamically adjust URL in settings page
Browse files Browse the repository at this point in the history
  • Loading branch information
rugk committed May 13, 2021
1 parent 8fe1a92 commit 8773818
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 23 deletions.
27 changes: 27 additions & 0 deletions src/common/modules/BrowserCompat.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/**
* Helper functions useful for ensuring browser compatibility.
*
* @public
* @module BrowserCompat
*/

/**
* Returns a value based on what browser this is running in.
*
* @private
* @param {Object} switchBrowser an object with values to return per browser
* @returns {string}
*/
export async function getBrowserValue(switchBrowser) {
if (browser.runtime.getBrowserInfo) {
const browserInfo = await browser.runtime.getBrowserInfo();

if (browserInfo.name === "Thunderbird") {
return switchBrowser.thunderbird;
} else {
return switchBrowser.firefox;
}
} else {
return switchBrowser.chrome;
}
}
24 changes: 2 additions & 22 deletions src/common/modules/data/Tips.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@
* @return {boolean|null}
*/

import {userSpeaksLocaleNotYetTranslated} from "../LanguageHelper.js";
import { userSpeaksLocaleNotYetTranslated } from "../LanguageHelper.js";
import { getBrowserValue } from "../BrowserCompat.js";

/**
* An array of all tips.
Expand Down Expand Up @@ -169,27 +170,6 @@ const tipArray = [
}
];

/**
* Returns a value based on what browser this is running in.
* @private
* @param {Object} switchBrowser an object with values to return per browser
* @returns {string}
*/
async function getBrowserValue(switchBrowser) {
if (browser.runtime.getBrowserInfo) {
const browserInfo = await browser.runtime.getBrowserInfo();

if (browserInfo.name === "Thunderbird") {
return switchBrowser.thunderbird;
} else {
return switchBrowser.firefox;
}
} else {
return switchBrowser.chrome;
}
}

// freeze the inner tip objects, this is strongly recommend
tipArray.forEach((object) => Object.freeze(object));

Expand Down
2 changes: 1 addition & 1 deletion src/options/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ <h1 data-i18n="__MSG_titleUnicodeAutocorrection__">Unicode autocorrection</h1>
Only the quotes replacement is done immediately.
</span><br>
<span class="helper-text" data-i18n="__MSG_optionHelperTextAutocorrectionEmoji__" data-opt-i18n-keep-children>
For Emoji autocorrection, including <code data-i18n="__MSG_optionHelperTextAutocorrectionEmojiColonsCode__">:colon:</code> shortcodes and Emoticons, please also try out our <a href="https://addons.mozilla.org/firefox/addon/awesome-emoji-picker/" data-i18n="__MSG_optionHelperTextAutocorrectionEmojiLinkText__" data-i18n-href="__MSG_optionHelperTextAutocorrectionEmojiLink__">🤩&nbsp;Awesome Emoji Picker</a> add-on.
For Emoji autocorrection, including <code data-i18n="__MSG_optionHelperTextAutocorrectionEmojiColonsCode__">:colon:</code> shortcodes and Emoticons, please also try out our <a id="link-awesome-emoji" data-i18n="__MSG_optionHelperTextAutocorrectionEmojiLinkText__">🤩&nbsp;Awesome Emoji Picker</a> add-on.
</span>

<li>
Expand Down
9 changes: 9 additions & 0 deletions src/options/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/

import { tips } from "/common/modules/data/Tips.js";
import { getBrowserValue } from "/common/modules/BrowserCompat.js";
import * as AddonSettings from "/common/modules/AddonSettings/AddonSettings.js";
import * as AutomaticSettings from "/common/modules/AutomaticSettings/AutomaticSettings.js";
import * as RandomTips from "/common/modules/RandomTips/RandomTips.js";
Expand All @@ -20,3 +21,11 @@ RandomTips.init(tips).then(() => {
RandomTips.setContext("options");
RandomTips.showRandomTipIfWanted();
});

getBrowserValue({
firefox: "https://addons.mozilla.org/firefox/addon/awesome-emoji-picker/?utm_source=unicodify-addon&utm_medium=addon&utm_content=unicodify-addon-settings-inline&utm_campaign=unicodify-addon-settings-inline",
thunderbird: "https://addons.thunderbird.net/thunderbird/addon/awesome-emoji-picker/reviews/?utm_source=unicodify-addon&utm_medium=addon&utm_content=unicodify-addon-settings-inline&utm_campaign=unicodify-addon-settings-inline",
chrome: "https://chrome.google.com/webstore/detail/awesome-emoji-picker/",
}).then((browserUrl) => {
document.getElementById("link-awesome-emoji").href = browserUrl;
});

0 comments on commit 8773818

Please sign in to comment.