Custom gesture - utubo/firefox-simple_gesture GitHub Wiki

Javascript examples

see here(./Custom-gesture-examples)

API

You can use some API.

Tips with example

Input keyword and open google in a new tab

/**
 * @name google
 * SimpleGesture inputs the value of @name automatically in Setting-page.
 */
const q = prompt();
if (q) {
    /* You can use SimpleGesture.open(url) to open a new tab. */
    SimpleGesture.open('https://www.google.com/search?q=' + encodeURIComponent(q));
}

or

/**
 * @name google
 */
const q = prompt();
/* If the last evaluated statement has 'url' property,
   then Simple-Gesture opens it in a new tab. */
const newTab = q ? { url: ('https://www.google.com/search?q=' + encodeURIComponent(q)) } : null;
newTab;

Open target link in background

/**
 * @name Open in bg
 */
/* You can use "SimpleGesture.target" to get the gesture target. */
let target = SimpleGesture.target;
while (target && !target.href) {
  target = target.parentNode;
}
if (target) {
  SimpleGesture.open(target.href, { active: false });
}

or

/**
 * @name Open in bg
 */
/* You can use "SimpleGesture.target" to get the gesture target. */
let target = SimpleGesture.target;
while (target && !target.href) {
  target = target.parentNode;
}
/* If the last evaluated statement's 'active' property is false,
   then Simple-Gesture opens it in background. */
const newTab = target ? { url: target.href, active: false } : null;
newTab;

Show URL and open target link in current tab.

/**
 * @name Confirm URL
 */ 
for (let target = SimpleGesture.target; !!target; target = target.parentNode) {
  if (target.href) {
    if (confirm('Are you sure you want to open this URL?\n' + target.href)) {
      /* You can use "location.href" to open url in current tab. :) */
      location.href = target.href;
    }
    break;
  }
}

Other tips

Close current tab with user script.

You can use this code instead of window.close();

browser.runtime.sendMessage('close');

jp(./Custom-gesture-[jp])