Skip to content
This repository has been archived by the owner on Sep 22, 2020. It is now read-only.

Commit

Permalink
1.2.0 (#36)
Browse files Browse the repository at this point in the history
The release of 1.2.0 version.
  • Loading branch information
Amaimersion authored Aug 7, 2018
1 parent 300ac83 commit 99e5288
Show file tree
Hide file tree
Showing 9 changed files with 112 additions and 29 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
# 1.2.0 (7 августа, 2018)

## Расширение

### Новые функции

- Добавлена поддержка для зеркал [#32](Amaimersion/2ch-helper#32).

### Исправлено

- Исправлен баг, при котором изображения раскрывались при наведении курсора, даже если эта опция была выключена [#30](Amaimersion/2ch-helper#30).

### Изменено

- Теперь в Chromium браузерах разрешение `pageCapture` опционально. Теперь по умолчанию расширение не будет требовать доступ ко всем URL.

# 1.1.0 (17 июля, 2018)

Доступно в [Opera Web Store]().
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "2ch-helper",
"version": "1.1.0",
"version": "1.2.0",
"description": "A browser extension which facilitates interaction with the imageboard 2ch.hk.",
"scripts": {
"watch:chromium:dev": "webpack --watch --config webpack.config.dev --env.platform=chromium --env.dontRemove=true",
Expand Down
37 changes: 32 additions & 5 deletions src/interaction/js/background/download.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,17 +57,44 @@ export abstract class Download {
this._settings = await this.getSettings();
}

/**
* Checks for page download permission.
*
* @throws Throws an error if a user denied permission.
* @throws Throws an error if a browser not supported this feature.
*/
const checkPermission = async (): Promise<void> => {
await new Promise((resolve) => {
try {
chrome.permissions.request({
permissions: ["pageCapture"]
}, (granted) => {
if (!granted) {
throw new Error("Отказано в доступе");
}

return resolve();
});
} catch (error) {
// `pageCapture` permission not listed in manifest as a `optional_permissions`.
throw new Error("Не поддерживается браузером");
}
});

// ensure that chromium browsers support this.
if (!chrome.pageCapture || !chrome.pageCapture.saveAsMHTML) {
throw new Error("Не поддерживается браузером");
}
}

await checkPermission();
const activeTab = await API.getActiveTab();

/**
* Gets the MHTML content of the active page.
*/
const getMHTML = (): any => {
const getMHTML = (): Promise<any> => {
return new Promise<any>((resolve) => {
if (!chrome.pageCapture || !chrome.pageCapture.saveAsMHTML) {
throw new Error("Не поддерживается браузером");
}

chrome.pageCapture.saveAsMHTML({tabId: activeTab.id}, (data) => {
return resolve(URL.createObjectURL(data));
});
Expand Down
8 changes: 4 additions & 4 deletions src/interaction/js/content/DOMContentLoaded.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,14 @@ abstract class DOMContentLoaded {
* Checks if a current page is a thread.
*/
protected static checkForThread: CheckMethod = (location) => {
// (?<protocol>.*)(?<host>2ch\.hk)(?<board>\/.*\/)(?<resource>res\/)(?<thread>.*)(?<format>\.html)
const regexp = new RegExp(/(.*)(2ch\.hk)(\/.*\/)(res\/)(.*)(\.html)/, "");
// (?<protocol>.*)(?::\/\/)(?<host>2ch)(?:\.)(?<domain>.*)(?<board>\/.*\/)(?:res\/)(?<thread>.*)(?<format>\..*)
const regexp = new RegExp(/(.*)(:\/\/)(2ch)(\.)(.*)(\/.*\/)(res\/)(.*)(\..*)/, "");
return regexp.test(location.href);
}

protected static checkForBoard: CheckMethod = (location) => {
// (?<protocol>.*)(?<host>2ch\.hk)\/(?<board>\w*)(\/?)(#?)$
const regexp = new RegExp(/(.*)(2ch\.hk)\/(\w*)(\/?)(#?)$/, "m");
// (?<protocol>.*)(?::\/\/)(?<host>2ch)(?:\.)(?<domain>[^\/]*)\/(?<board>\w*)(\/?)(#?)$
const regexp = new RegExp(/(.*)(:\/\/)(2ch)(\.)([^\/]*)\/(\w*)(\/?)(#?)$/, "m");
return regexp.test(location.href);
}
}
Expand Down
17 changes: 13 additions & 4 deletions src/interaction/js/content/page-elements.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {API} from "@modules/api";
import {Script} from "@modules/communication";
import {Settings} from "@modules/settings";
import {UserSettings} from "@modules/storage-sync";


/**
Expand Down Expand Up @@ -141,10 +142,13 @@ abstract class Checkboxes {
* Observation for changes of the page.
*/
abstract class Observer {
private static _settings: UserSettings = undefined;

/**
* Runs when the page is loaded.
*/
public static main(): void {
public static async main(): Promise<void> {
this._settings = await Settings.get("settingsOther");
this.bindObserver();
}

Expand All @@ -171,14 +175,19 @@ abstract class Observer {
continue;
}

Images.bindExpand(node as Elements.Element);
Custom.createDownloadButtons(node as Elements.Post);

if (Observer.isReplyPost(node as Elements.Post)) {
Observer.replyPostEvent(node as Elements.Post);
} else {
Observer.commonPostEvent(node as Elements.Post);
}

if (Observer._settings.expandImageWhenTarget) {
Images.bindExpand(node as Elements.Element);
}

if (Observer._settings.downloadButtonNearFile) {
Custom.createDownloadButtons(node as Elements.Post);
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/interface/html/common/html5.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
block vars
- var version = "1.1.0";
- var version = "1.2.0";
- var year = "2018";
- var title = "2ch-helper";

Expand Down
20 changes: 14 additions & 6 deletions src/interface/js/popup.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,22 @@ interface ErrorArguments {


abstract class PageInfo {
protected static readonly threadUrls = [
"*://2ch.hk/*/res/*",
"*://2ch.pm/*/res/*",
"*://2ch.re/*/res/*",
"*://2ch.tf/*/res/*",
"*://2ch.wf/*/res/*",
"*://2ch.yt/*/res/*"
];
protected static readonly _elementsEvents: PopupElementEvent[] = [
{
selector: "#screenshot-of-posts",
type: "click",
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "screenshotPosts"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
);
}
Expand All @@ -35,7 +43,7 @@ abstract class PageInfo {
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "screenshotThread"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
);
}
Expand All @@ -46,7 +54,7 @@ abstract class PageInfo {
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "downloadImages"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
);
}
Expand All @@ -57,7 +65,7 @@ abstract class PageInfo {
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "downloadVideo"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
);
}
Expand All @@ -68,7 +76,7 @@ abstract class PageInfo {
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "downloadMedia"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
);
}
Expand All @@ -79,7 +87,7 @@ abstract class PageInfo {
event: () => {
Popup.defaultElementEvent(
{type: "command", command: "downloadThread"},
{url: "*://2ch.hk/*/res/*"},
{url: PageInfo.threadUrls},
{errorText: "Активный тред не найден"}
)
}
Expand Down
4 changes: 2 additions & 2 deletions src/manifest/chromium.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version_name": "1.1.0",
"version_name": "1.2.0",

"options_ui": {
"chrome_style": true
Expand All @@ -9,7 +9,7 @@
"persistent": false
},

"permissions": [
"optional_permissions": [
"pageCapture"
]
}
35 changes: 29 additions & 6 deletions src/manifest/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

"name": "2ch-helper",
"short_name": "2ch-helper",
"version": "1.1.0",
"version": "1.2.0",
"description": "Облегчение взаимодействия с имиджбордой 2ch.hk.",

"author": "Sergey Kuznetsov",
Expand Down Expand Up @@ -34,12 +34,30 @@

"content_scripts": [
{
"matches": ["*://2ch.hk/*"],
"js": ["/interaction/js/content.js"]
"matches": [
"*://2ch.hk/*",
"*://2ch.pm/*",
"*://2ch.re/*",
"*://2ch.tf/*",
"*://2ch.wf/*",
"*://2ch.yt/*"
],
"js": [
"/interaction/js/content.js"
]
},
{
"matches": ["*://2ch.hk/*/res/*"],
"css": ["/interaction/css/custom-thread.css"]
"matches": [
"*://2ch.hk/*/res/*",
"*://2ch.pm/*/res/*",
"*://2ch.re/*/res/*",
"*://2ch.tf/*/res/*",
"*://2ch.wf/*/res/*",
"*://2ch.yt/*/res/*"
],
"css": [
"/interaction/css/custom-thread.css"
]
}
],

Expand All @@ -54,7 +72,12 @@
"downloads",
"activeTab",
"notifications",
"*://2ch.hk/*"
"*://2ch.hk/*",
"*://2ch.pm/*",
"*://2ch.re/*",
"*://2ch.tf/*",
"*://2ch.wf/*",
"*://2ch.yt/*"
],

"web_accessible_resources": [
Expand Down

0 comments on commit 99e5288

Please sign in to comment.