aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorRahiel Kasim <rahielkasim@gmail.com>2019-04-07 15:21:51 +0200
committerRahiel Kasim <rahielkasim@gmail.com>2019-04-07 15:21:51 +0200
commit0ea87f7498b0a6090e310cb1f057b2e336082f4b (patch)
treeeca84079b2a8e7a0daa0155edb240519b4611d97
parent110bc0e03ef52d89ee6197bc7fc63ae6bbba66dd (diff)
fix background archiving on archive.is
-rw-r--r--.eslintrc.json3
-rw-r--r--package.json19
-rw-r--r--src/archiveror.js33
3 files changed, 36 insertions, 19 deletions
diff --git a/.eslintrc.json b/.eslintrc.json
index 3cf1937..7e82c67 100644
--- a/.eslintrc.json
+++ b/.eslintrc.json
@@ -7,7 +7,8 @@
},
"extends": "eslint:recommended",
"parserOptions": {
- "sourceType": "module"
+ "sourceType": "module",
+ "ecmaVersion": 8
},
"rules": {
"indent": ["error", 4],
diff --git a/package.json b/package.json
index 5667f1f..dc0e0b8 100644
--- a/package.json
+++ b/package.json
@@ -16,19 +16,22 @@
"bugs": {
"url": "https://github.com/rahiel/archiveror/issues"
},
+ "dependencies": {
+ "@babel/polyfill": "^7.4.3"
+ },
"devDependencies": {
- "@babel/core": "^7.1.6",
- "@babel/preset-env": "^7.1.6",
- "babel-loader": "^8.0.4",
- "eslint": "^5.9.0",
+ "@babel/core": "^7.4.3",
+ "@babel/preset-env": "^7.4.3",
+ "babel-loader": "^8.0.5",
+ "eslint": "^5.16.0",
"source-map-loader": "^0.2.4",
- "web-ext": "^2.9.2",
- "webpack": "^4.26.1",
- "webpack-cli": "^3.1.2"
+ "web-ext": "^3.0.0",
+ "webpack": "^4.29.6",
+ "webpack-cli": "^3.3.0"
},
"browserslist": [
"firefox >= 52",
- "chrome >= 48"
+ "chrome >= 55"
],
"babel": {
"presets": [
diff --git a/src/archiveror.js b/src/archiveror.js
index 77e4390..8225985 100644
--- a/src/archiveror.js
+++ b/src/archiveror.js
@@ -1,3 +1,5 @@
+import "@babel/polyfill";
+
import {
defaults, getArchivingURL, hasPageCapture, isLocal, makeFilename, sanitizeFilename, services, writeClipboard
} from "./utils.js";
@@ -6,17 +8,28 @@ import {
function archive_is(url) {
if (isLocal(url)) return;
const service = "archive.is";
- let request = new XMLHttpRequest();
- request.open("POST", "https://archive.is/submit/", true);
- request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
- let params = "url=" + encodeURIComponent(url);
- request.onreadystatechange = function () {
- if (request.readyState === 4) {
- let link = request.responseURL;
+ fetch("https://archive.is")
+ .then(response => response.text())
+ .then(async (text) => {
+ let html = new DOMParser().parseFromString(text, "text/html");
+ let submitid = html.querySelector(`input[name="submitid"]`).value;
+
+ let response = await fetch("https://archive.is/submit/", {
+ method: "POST",
+ headers: {"Content-Type": "application/x-www-form-urlencoded"},
+ body: "url=" + encodeURIComponent(url) + "&submitid=" + encodeURIComponent(submitid)
+ });
+ let link;
+ if (response.url.includes("/submit")) {
+ let text = await response.text();
+ let html = new DOMParser().parseFromString(text, "text/html");
+ let re = /"(https?:\/\/archive\..+?\/.+?)"/;
+ link = text.match(re)[1];
+ } else {
+ link = response.url;
+ }
postArchive(url, service, link);
- }
- };
- request.send(params);
+ });
}
function archive_org(url) {