Implement ^,$ navigating to 0%,100% in x-direction

This is made possible by also allowing the second
argument to be "x" or "y". We supply "y" as the
default to retain the current, more commonly
desired behavior.
This commit is contained in:
Koushien 2017-12-08 21:11:40 -08:00 committed by Colin Caine
parent 6e9bf93665
commit 850104e0fe
2 changed files with 24 additions and 17 deletions

View file

@ -44,6 +44,9 @@ const DEFAULTS = o({
"l": "scrollpx 50", "l": "scrollpx 50",
"G": "scrollto 100", "G": "scrollto 100",
"gg": "scrollto 0", "gg": "scrollto 0",
"$": "scrollto 100 x",
// "0": "scrollto 0 x", // will get interpreted as a count
"^": "scrollto 0 x",
"H": "back", "H": "back",
"L": "forward", "L": "forward",
"d": "tabclose", "d": "tabclose",

View file

@ -186,21 +186,25 @@ export function scrollpx(a: number, b: number) {
window.scrollBy(a, b) window.scrollBy(a, b)
} }
/** If one argument is given, scroll to that percentage down the page. /** If two numbers are given, treat as x and y values to give to window.scrollTo
If two arguments are given, treat as x and y values to give to window.scrollTo If one number is given, scroll to that percentage along a chosen axis,
defaulting to the y-axis
*/ */
//#content //#content
export function scrollto(a: number, b?: number) { export function scrollto(a: number, b: number | "x" | "y" = "y") {
a = Number(a) a = Number(a)
// if b is undefined, Number(b) is NaN. if (b === "y") {
b = Number(b) window.scrollTo(
window.scrollTo( window.scrollX,
b ? a : window.scrollX, a.clamp(0, 100) * window.document.scrollingElement.scrollHeight / 100)
b }
? b else if (b === "x") {
: a.clamp(0, 100) * window.scrollTo(
(window.document.scrollingElement.scrollHeight / 100) a.clamp(0, 100) * window.document.scrollingElement.scrollWidth / 100,
) window.scrollY)
} else {
window.scrollTo(a, Number(b)) // a,b numbers
}
} }
//#content //#content
@ -272,7 +276,7 @@ export function open(...urlarr: string[]) {
/** Go to your homepage(s) /** Go to your homepage(s)
@param all @param all
- if "true", opens all homepages in new tabs - if "true", opens all homepages in new tabs
- if "false" or not given, opens the last homepage in the current tab - if "false" or not given, opens the last homepage in the current tab
@ -1214,7 +1218,7 @@ export async function sanitize(...args: string[]) {
Afterwards use go[key], gn[key], or gw[key] to [[open]], [[tabopen]], or Afterwards use go[key], gn[key], or gw[key] to [[open]], [[tabopen]], or
[[winopen]] the URL respectively. [[winopen]] the URL respectively.
*/ */
//#background //#background
export async function quickmark(key: string, ...addressarr: string[]) { export async function quickmark(key: string, ...addressarr: string[]) {
@ -1249,7 +1253,7 @@ export function get(target: string, property?: string){
(i.e. not nmaps.) (i.e. not nmaps.)
It can be used on any string <-> string settings found [here](/static/docs/modules/_config_.html#defaults) It can be used on any string <-> string settings found [here](/static/docs/modules/_config_.html#defaults)
*/ */
//#background //#background
export function set(setting: string, ...value: string[]){ export function set(setting: string, ...value: string[]){
@ -1431,13 +1435,13 @@ export async function ttscontrol(action: string) {
/** Add or remove a bookmark. /** Add or remove a bookmark.
* *
* Optionally, you may give the bookmark a title. If no URL is given, a bookmark is added for the current page. * Optionally, you may give the bookmark a title. If no URL is given, a bookmark is added for the current page.
* *
* If a bookmark already exists for the URL, it is removed. * If a bookmark already exists for the URL, it is removed.
*/ */
//#background //#background
export async function bmark(url?: string, ...titlearr: string[] ){ export async function bmark(url?: string, ...titlearr: string[] ){
url = url === undefined ? (await activeTab()).url : url url = url === undefined ? (await activeTab()).url : url
let title = titlearr.join(" ") let title = titlearr.join(" ")
let dupbmarks = await browser.bookmarks.search({url}) let dupbmarks = await browser.bookmarks.search({url})
dupbmarks.map((bookmark) => browser.bookmarks.remove(bookmark.id)) dupbmarks.map((bookmark) => browser.bookmarks.remove(bookmark.id))
if (dupbmarks.length == 0 ) {browser.bookmarks.create({url, title})} if (dupbmarks.length == 0 ) {browser.bookmarks.create({url, title})}