-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 support for most search engines #31
Changes from 10 commits
2e2d092
bb9968a
c4e4708
9a957c5
df7b43a
dbe6643
97408b1
b3a92ae
e9bd8a2
ee69cad
f8e8893
2102926
2532e3b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
/** | ||
* @typedef {object} SiteConfig | ||
* @property {string[]} inputName - input element name of search box | ||
* @property {string[]} sidebarContainerId - prepend child to | ||
* @property {string[]} sidebarContainerClass - if above ids not exist, prepend child to | ||
* @property {string[]} appendContainerId - if above all not exist, append child to | ||
* @property {string[]} appendContainerClass - if above all not exist, append child to | ||
*/ | ||
/** | ||
* @type {Object.<string,SiteConfig>} | ||
*/ | ||
export const config = { | ||
google: { | ||
inputName: ["q"], | ||
sidebarContainerId: ["rhs"], | ||
sidebarContainerClass: [], | ||
appendContainerId: ["rcnt"], | ||
appendContainerClass: [] | ||
}, | ||
bing: { | ||
inputName: ["q"], | ||
sidebarContainerId: ["b_context"], | ||
sidebarContainerClass: [], | ||
appendContainerId: [], | ||
appendContainerClass: [] | ||
}, | ||
yahoo: { | ||
inputName: ["p"], | ||
sidebarContainerId: ["right"], | ||
sidebarContainerClass: ["Contents__inner Contents__inner--sub"], | ||
appendContainerId: ["cols", "contents__wrap"], // and yahoo jp | ||
appendContainerClass: [] | ||
}, | ||
duckduckgo: { | ||
inputName: ["q"], | ||
sidebarContainerId: [], | ||
sidebarContainerClass: ["results--sidebar js-results-sidebar"], | ||
appendContainerId: ["links_wrapper"], | ||
appendContainerClass: [] | ||
}, | ||
startpage: { | ||
inputName: ["query"], | ||
sidebarContainerId: [], | ||
sidebarContainerClass: ["layout-web__sidebar layout-web__sidebar--web"], | ||
appendContainerId: [], | ||
appendContainerClass: ["layout-web__body layout-web__body--desktop"] | ||
}, | ||
baidu: { | ||
inputName: ["wd"], | ||
sidebarContainerId: ["content_right"], | ||
sidebarContainerClass: [], | ||
appendContainerId: ["container"], | ||
appendContainerClass: [] | ||
}, | ||
kagi: { | ||
inputName: ["q"], | ||
sidebarContainerId: [], | ||
sidebarContainerClass: ["right-content-box _0_right_sidebar"], | ||
appendContainerId: ["_0_app_content"], | ||
appendContainerClass: [] | ||
}, | ||
yandex: { | ||
inputName: ["text"], | ||
sidebarContainerId: ["search-result-aside"], | ||
sidebarContainerClass: [], | ||
appendContainerId: [], | ||
appendContainerClass: [] | ||
}, | ||
naver: { | ||
inputName: ["query"], | ||
sidebarContainerId: ["sub_pack"], | ||
sidebarContainerClass: [], | ||
appendContainerId: ["content"], | ||
appendContainerClass: [] | ||
}, | ||
brave: { | ||
inputName: ["q"], | ||
sidebarContainerId: ["side-right"], | ||
sidebarContainerClass: [], | ||
appendContainerId: [], | ||
appendContainerClass: [] | ||
}, | ||
searx: { | ||
inputName: ["q"], | ||
sidebarContainerId: ["sidebar_results"], | ||
sidebarContainerClass: [], | ||
appendContainerId: [], | ||
appendContainerClass: [] | ||
}, | ||
ecosia: { | ||
inputName: ["q"], | ||
sidebarContainerId: [], | ||
sidebarContainerClass: ["sidebar web__sidebar"], | ||
appendContainerId: ["main"], | ||
appendContainerClass: [] | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
export function getPossibleElementByNameArray(elementNameArray) { | ||
for (const elementName of elementNameArray) { | ||
const element = document.getElementsByName(elementName)[0]; | ||
if (element) { | ||
return element; | ||
} | ||
} | ||
} | ||
|
||
export function getPossibleElementByIdArray(elementIdArray) { | ||
for (const elementId of elementIdArray) { | ||
const element = document.getElementById(elementId); | ||
if (element) { | ||
return element; | ||
} | ||
} | ||
} | ||
|
||
export function getPossibleElementByClassArray(elementClassArray) { | ||
for (const elementClass of elementClassArray) { | ||
const element = document.getElementsByClassName(elementClass)[0]; | ||
if (element) { | ||
return element; | ||
} | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd prefer using simple There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry I don't know what happened when I wrote this code, it does seem like a long and incomprehensible way 😂 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can combine id and class, by using querySelector
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok, wait a minute
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@wong2 finished