Skip to content

Commit

Permalink
feat: show release notes when the extension has been updated #236
Browse files Browse the repository at this point in the history
  • Loading branch information
Robot-Inventor committed Oct 16, 2023
1 parent d5bfda7 commit d435e15
Show file tree
Hide file tree
Showing 19 changed files with 85 additions and 87 deletions.
3 changes: 0 additions & 3 deletions _locales/en/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@
},
"settingsPleaseReload": {
"message": "Please reload Twitter once you have changed the settings"
},
"ShadowbanScannerUpdatedTov2": {
"message": "Shadowban Scanner has been updated to v2! Click <a href=\"https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/en/\" target=\"_blank\">here</a> for details."
}
}
3 changes: 0 additions & 3 deletions _locales/ja/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@
},
"settingsPleaseReload": {
"message": "設定を変更したらTwitterを再読み込みしてください。"
},
"ShadowbanScannerUpdatedTov2": {
"message": "Shadowban Scannerがv2にアップデートされました!詳細は<a href=\"https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/\" target=\"_blank\">こちら</a>"
}
}
3 changes: 0 additions & 3 deletions _locales/ko/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@
},
"settingsPleaseReload": {
"message": "설정을 변경한 후 Twitter를 다시 로드해주세요"
},
"ShadowbanScannerUpdatedTov2": {
"message": "Shadowban Scanner has been updated to v2! Click <a href=\"https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/en/\" target=\"_blank\">here</a> for details."
}
}
3 changes: 0 additions & 3 deletions _locales/zh_TW/messages.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,5 @@
},
"settingsPleaseReload": {
"message": "若更改設定,請重新載入 Twitter"
},
"ShadowbanScannerUpdatedTov2": {
"message": "Shadowban Scanner has been updated to v2! Click <a href=\"https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/en/\" target=\"_blank\">here</a> for details."
}
}
7 changes: 7 additions & 0 deletions manifest/v2.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@
]
}
],
"background": {
"scripts": [
"dist/polyfill/browserPolyfill.min.js",
"dist/js/background.js"
],
"persistent": false
},
"web_accessible_resources": [
"dist/js/pageScript.js",
"dist/image/*"
Expand Down
4 changes: 4 additions & 0 deletions manifest/v3.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@
]
}
],
"background": {
"service_worker": "dist/js/background.js",
"persistent": false
},
"web_accessible_resources": [
{
"resources": [
Expand Down
28 changes: 28 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
"homepage": "https://github.com/Robot-Inventor/shadowban-scanner#readme",
"dependencies": {
"@material/web": "^1.0.0",
"@types/chrome": "^0.0.246",
"@typescript-eslint/eslint-plugin": "^6.2.0",
"@typescript-eslint/parser": "^6.2.0",
"colors": "^1.4.0",
Expand Down
1 change: 0 additions & 1 deletion src/ts/@types/common/settings.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,4 @@ export interface Settings {
showMessagesInUnproblematicTweets: boolean;
showNotesInMessages: boolean;
showTweetButton: boolean;
hasDisplayedV2UpdateBanner: boolean;
}
3 changes: 1 addition & 2 deletions src/ts/@types/common/settings.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export function isSettings(obj: unknown): obj is Settings {
typeof typedObj["enableOnlyForCurrentUsersTweets"] === "boolean" &&
typeof typedObj["showMessagesInUnproblematicTweets"] === "boolean" &&
typeof typedObj["showNotesInMessages"] === "boolean" &&
typeof typedObj["showTweetButton"] === "boolean" &&
typeof typedObj["hasDisplayedV2UpdateBanner"] === "boolean"
typeof typedObj["showTweetButton"] === "boolean"
)
}
19 changes: 19 additions & 0 deletions src/ts/background.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
chrome.runtime.onInstalled.addListener((details) => {
const isJapanese = chrome.i18n.getUILanguage() === "ja";

if (details.reason === chrome.runtime.OnInstalledReason.UPDATE) {
const releaseNoteURL = isJapanese
? "https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/"
: "https://robot-inventor.github.io/article/2023/09/30/shadowban-scanner-v2-release/en/";
void chrome.tabs.create({ url: releaseNoteURL });

return;
}

if (details.reason === chrome.runtime.OnInstalledReason.INSTALL) {
const welcomeURL = isJapanese
? "https://github.com/Robot-Inventor/shadowban-scanner/blob/main/README_ja.md"
: "https://github.com/Robot-Inventor/shadowban-scanner/blob/main/README.md";
void chrome.tabs.create({ url: welcomeURL });
}
});
1 change: 0 additions & 1 deletion src/ts/common/defaultSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { Settings } from "../@types/common/settings";
const DEFAULT_SETTINGS = {
alwaysDetailedView: false,
enableOnlyForCurrentUsersTweets: false,
hasDisplayedV2UpdateBanner: false,
showMessagesInUnproblematicTweets: false,
showNotesInMessages: true,
showTweetButton: true
Expand Down
11 changes: 8 additions & 3 deletions src/ts/common/migrator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,15 @@
* @returns {Promise<void>}
*/
const migrateFromV1ToV2 = async () => {
const v1Settings = await browser.storage.local.get(null);
if (!("showMessageInAllTweets" in v1Settings)) return;
const currentSettings = await browser.storage.local.get(null);

await browser.storage.local.set({ showMessagesInUnproblematicTweets: v1Settings.showMessageInAllTweets });
if ("hasDisplayedV2UpdateBanner" in currentSettings) {
await browser.storage.local.remove("hasDisplayedV2UpdateBanner");
}

if (!("showMessageInAllTweets" in currentSettings)) return;

await browser.storage.local.set({ showMessagesInUnproblematicTweets: currentSettings.showMessageInAllTweets });
await browser.storage.local.remove("showMessageInAllTweets");
};

Expand Down
52 changes: 0 additions & 52 deletions src/ts/contentScript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,64 +3,12 @@ import { DEFAULT_SETTINGS } from "./common/defaultSettings";
import { Translator } from "./common/translator";
import { migrateFromV1ToV2 } from "./common/migrator";

// eslint-disable-next-line max-statements
const showV2Banner = () => {
const banner = document.createElement("div");
banner.id = "shadowban-scanner-banner";
banner.innerHTML = browser.i18n.getMessage("ShadowbanScannerUpdatedTov2");

const style = document.createElement("style");
style.textContent = `
#shadowban-scanner-banner {
position: fixed;
top: 0;
text-align: center;
width: 100vw;
padding: 0.5rem 0;
background-color: rgb(29, 155, 240);
color: white;
font-family: sans-serif;
}
#shadowban-scanner-banner a {
color: white;
text-decoration: underline;
}
#shadowban-scanner-banner button {
font-size: 1.5rem;
position: absolute;
top: 0;
right: 1rem;
background-color: transparent;
border: none;
color: white;
cursor: pointer;
}
`;

const closeButton = document.createElement("button");
closeButton.textContent = "×";
closeButton.addEventListener("click", () => {
banner.remove();
});

banner.appendChild(closeButton);
document.body.appendChild(style);
document.body.appendChild(banner);
};

// eslint-disable-next-line max-statements
const main = async () => {
await migrateFromV1ToV2();

const settings = await browser.storage.local.get(DEFAULT_SETTINGS);

if (!settings.hasDisplayedV2UpdateBanner) {
showV2Banner();
await browser.storage.local.set({ hasDisplayedV2UpdateBanner: true });
}

const translator = new Translator(browser.i18n.getMessage, browser.runtime.getURL("dist/image/"));

const eventGenerator = document.createElement("div");
Expand Down
16 changes: 8 additions & 8 deletions userScript/en.user.js

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions userScript/ja.user.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions userScript/ko.user.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions userScript/zh_TW.user.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ module.exports = {
"./js/browserAction.js": "./src/ts/browserAction.ts",
"./js/contentScript.js": "./src/ts/contentScript.ts",
"./js/pageScript.js": "./src/ts/pageScript.ts",
"./js/background.js": "./src/ts/background.ts",
...userScriptEntries
},
output: {
Expand Down

0 comments on commit d435e15

Please sign in to comment.