Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add ieee function #7

Merged
merged 4 commits into from
Jun 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 1 addition & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

![build](https://github.com/chibat/chrome-extension-typescript-starter/workflows/build/badge.svg)

Chrome Extension, register paper of acmdl, to scrapbox
Chrome Extension, register paper of acmdl and ieee, to scrapbox

download: [Chrome webstore](https://chrome.google.com/webstore/detail/scrap-paper/cgkgikddogobbaakbmbjphgipgfbkbdo)

Expand All @@ -20,12 +20,6 @@ download: [Chrome webstore](https://chrome.google.com/webstore/detail/scrap-pape
* Webpack
* React
* Jest
* Example Code
* Chrome Storage
* Options Version 2
* content script
* count up badge number
* background

## Project Structure

Expand Down
10 changes: 7 additions & 3 deletions public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"manifest_version": 3,

"name": "Scrap Paper",
"description": "Chrome Extension, register paper of acmdl, to scrapbox",
"version": "0.2",
"description": "Chrome Extension, register paper of acmdl and ieee, to scrapbox",
"version": "0.4",

"options_ui": {
"page": "options.html"
Expand All @@ -15,7 +15,11 @@

"content_scripts": [
{
"matches": ["https://dl.acm.org/doi/*"],
"matches": [
"https://dl.acm.org/doi/*",
"https://ieeexplore.ieee.org/document/*",
"https://ieeexplore.ieee.org/abstract/document/*"
],
"js": ["js/vendor.js", "js/content_script.js"]
}
],
Expand Down
9 changes: 5 additions & 4 deletions src/background.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
var data = { project: "" };
chrome.action.onClicked.addListener((tab: chrome.tabs.Tab) => {
chrome.storage.sync.get("project", (value) => {
if (tab.id == undefined) {
console.log("undefined.");
return;
}
var proj: string = "";
proj = value["project"];
if (proj == "" || proj == undefined) {
data.project = value["project"] ?? "";
if (data.project == "" || data.project == undefined) {
chrome.tabs.create({ url: "options.html" });
} else {
chrome.tabs.sendMessage(tab.id, proj, (response) => {});
console.log(data);
chrome.tabs.sendMessage(tab.id, data, (response) => {});
}
});
});
Expand Down
67 changes: 59 additions & 8 deletions src/content_script.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
registerScrapBox(request);

chrome.runtime.onMessage.addListener((data, sender, sendResponse) => {
const url: string = location.href;
if (url.includes("acm")) {
registerAcmScrapBox(data.project);
} else if (url.includes("ieee")) {
registerIeeeScrapBox(data.project);
}
sendResponse("from content script");
});

function registerScrapBox(proj: string) {
function registerAcmScrapBox(proj: string) {
const url: string = location.href;

const addLink = (text: string) => {
return "[" + text + "]";
};

const title_collection = document.getElementsByClassName(
"citation__title"
) as HTMLCollectionOf<HTMLElement>;
Expand Down Expand Up @@ -64,3 +64,54 @@ function registerScrapBox(proj: string) {
body
);
}
function registerIeeeScrapBox(proj: string) {
const url: string = location.href;
const title_collection = document.getElementsByClassName(
"document-title"
) as HTMLCollectionOf<HTMLElement>;
const title = title_collection[0].children[0].textContent ?? "";
console.log(title);

const author_collection = document.getElementsByClassName(
"authors-info-container"
) as HTMLCollectionOf<HTMLElement>;
const authors = Array.from(author_collection[0].children).map((e) => {
const author =
e.children[0].children[0].children[0].children[0].textContent;
return addLink(author);
});
console.log(authors);
const conference_collection = document.getElementsByClassName(
"stats-document-abstract-publishedIn"
);
const conference = conference_collection[1].textContent;
const abstract =
document.getElementsByClassName("abstract-text")[0].children[0].children[0]
.children[1].textContent;
const lines: string =
url +
"\n" +
addLink(conference) +
" " +
"\n" +
authors.join(", ") +
"\n\n" +
">" +
abstract +
"\n\n" +
"#survey";

var body = encodeURIComponent(lines);
window.open(
"https://scrapbox.io/" +
proj +
"/" +
encodeURIComponent(title.trim()) +
"?body=" +
body
);
}

const addLink = (text: string | null) => {
return "[" + text + "]";
};