Skip to content

Commit

Permalink
Branch to demo joker
Browse files Browse the repository at this point in the history
  • Loading branch information
Kapaya committed May 5, 2021
1 parent 156cc98 commit a8e311c
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 26 deletions.
10 changes: 10 additions & 0 deletions src/formula.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import ohm from 'ohm-js/dist/ohm';
import _ from "lodash";
import { Attribute, Record } from './core/types';
import stringHash from 'string-hash'
import { extractNumber } from './utils';

// An object to store results of calling functions
const functionCache = {}
Expand Down Expand Up @@ -165,6 +166,15 @@ const functions = {
"left": "The beginning string value.",
},
},
"ExtractNumber": {
"function": function(arg) {
arg = arg instanceof HTMLElement ? arg.textContent : arg;
return promisify(extractNumber(arg))
},
"help": {
"text": "The string value to extract the number from."
}
},
"Substring": {
"function": function(arg, indexStart, indexEnd = undefined) {
arg = arg instanceof HTMLElement ? arg.textContent : arg;
Expand Down
2 changes: 1 addition & 1 deletion src/site_adapters/github.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const GithubAdapter = createDomScrapingAdapter({
let name_el = el.querySelector('a[itemprop="name codeRepository"]')
let name = name_el.textContent.trim()

let stars_el = el.querySelector('*[href*="/stargazers"')
let stars_el = el.querySelector('*[href*="/stargazers"]')
let stars = extractNumber(stars_el, 0)

let forks_el = el.querySelector('*[href*="/network/members"]')
Expand Down
6 changes: 3 additions & 3 deletions src/ui/WcPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,17 @@ const WcPanel = ({ records = [], attributes, query, actions, adapter }) => {
onClick={() => {
setCreatingAdapter(true);
chrome.runtime.sendMessage({ command: 'editAdapter' });
}}> Edit Wildcard Table
}}> Edit Joker Table
</EditButton>
<ToggleButton hidden={hidden} onClick={ () => setHidden(!hidden)}
codeEditorHidden={codeEditorHidden}>
{ hidden ? "↑ Open Wildcard Table" : "↓ Close Wildcard Table" }
{ hidden ? "↑ Open Joker Table" : "↓ Close Joker Table" }
</ToggleButton>
</>
)}
<Panel hidden={hidden} codeEditorHidden={codeEditorHidden}>
<ControlBar>
<strong>Wildcard v0.2</strong>
<strong>Joker</strong>
<AutosuggestInput
activeCellValue={activeCellValue}
setActiveCellValue={setActiveCellValue}
Expand Down
63 changes: 41 additions & 22 deletions src/wildcard-background.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,28 +70,47 @@ chrome.runtime.onMessage.addListener(
});

chrome.contextMenus.create({
title: "Wildcard",
id: "wildcard",
title: "Joker",
id: "joker",
type: "normal",
contexts: ["page"]
}, () => {
chrome.contextMenus.create({
title: "Create Adapter",
contexts: ["page"],
parentId: "wildcard",
onclick: function () {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs && tabs.length) {
// send message to active tab
chrome.tabs.sendMessage(tabs[0].id, { command: "createAdapter" }, (response) => {
if (response.error) {
alert(response.error);
}
});
}
});
}
});
contexts: ["page"],
onclick: function () {
chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
if (tabs && tabs.length) {
// send message to active tab
chrome.tabs.sendMessage(tabs[0].id, { command: "createAdapter" }, (response) => {
if (response.error) {
alert(response.error);
}
});
}
});
}
});

// chrome.contextMenus.create({
// title: "Wildcard",
// id: "wildcard",
// type: "normal",
// contexts: ["page"]
// }, () => {
// chrome.contextMenus.create({
// title: "Create Adapter",
// contexts: ["page"],
// parentId: "wildcard",
// onclick: function () {
// chrome.tabs.query({ active: true, currentWindow: true }, (tabs) => {
// if (tabs && tabs.length) {
// // send message to active tab
// chrome.tabs.sendMessage(tabs[0].id, { command: "createAdapter" }, (response) => {
// if (response.error) {
// alert(response.error);
// }
// });
// }
// });
// }
// });
// chrome.contextMenus.create({
// title: "Edit Adapter",
// contexts: ["page"],
Expand All @@ -117,4 +136,4 @@ chrome.contextMenus.create({
// chrome.runtime.openOptionsPage();
// }
// });
});
//});

0 comments on commit a8e311c

Please sign in to comment.