Coder Social home page Coder Social logo

moz-showforpage's Introduction

ShowForPage for Mozilla Add-on SDK

The experimental showforpage API allows for acting on page load related events.

Usage

var showForPage = require('showforpage').ShowForPage,
  listeners;

exports.main = function () {
  listeners = showForPage({
    onLocationChange : checkUrl,
    onPageShow : checkForStuffInHTML
  });
};

exports.onUnload = function (reason) {
  if (reason !== 'shutdown') {
    listeners.remove();
  }
};

Options

  • onLocationChange - a callback that's called when the URL is changed. (optional)
  • onPageShow - a callback that's called when the page has loaded. (optional)
  • onLink - a callback that's called when a new link element has been added to the page. (optional)

Option syntax: onLocationChange

Should be a function. Is called with the URL of the current page as a single argument and has the document of the page that is checked as its context.

Option syntax: onPageShow

Same as onLocationChange but also includes an additional second parameter that is true if the background page is loaded in background and otherwise false. That second parameter is useful as it indicates that onLocationChange likely hasn't been called prior to onPageShow.

Option syntax: onLink

Should be a function. Is called with the URL of the current page as its first argument, an object containing all link data as its second argument (rels, href and title) and includes a last parameter like onPageShow that indicates if the page is loaded in the background. The function is called with the link element as its context.

How to use

Follow the Add-on SDK's documentation for third party packages.

Other modules usable with this one

In action in

  • Flattr Firefox Add-on: Source

Changelog

0.2.2

  • Support for Firefox 29 by no longer using the tab-browser SDK module

0.2.1

  • Support for Mozilla's Add-on SDK version 1.13b1

0.2.0

  • New onLink listener that listens for new link elements that are added to the page
  • No longer triggers onPageShow events on hash changes and tab selects - use onLocationChange change for that
  • onLocationChange is now called in the context of the page document and is given a second parameter indicating whether the document has been loaded
  • Triggers onLocationChange on active tabs on initialization

0.1.0

  • Moved the onLocationChange and onPageShow listeners, that were called when a new page was loaded, in the UrlbarButton module into this new module and then also removed the callbacks that were included as an argument when those listeners were called.

moz-showforpage's People

Contributors

voxpelli avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.