Skip to content

Commit

Permalink
v4: No deps, native URL object, new auto cfg
Browse files Browse the repository at this point in the history
  • Loading branch information
russellsteadman committed Oct 15, 2021
1 parent ac2b315 commit dd19d6a
Show file tree
Hide file tree
Showing 32 changed files with 396 additions and 407 deletions.
22 changes: 18 additions & 4 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,36 @@
/* eslint-disable */

module.exports = {
env: {
browser: true,
node: true,
es6: true,
},
extends: ['eslint:recommended', 'google', '@typescript-eslint/recommended'],
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:@typescript-eslint/recommended-requiring-type-checking',
'prettier',
],
globals: {
Atomics: 'readonly',
SharedArrayBuffer: 'readonly',
},
parser: '@typescript-eslint/parser',
parserOptions: {
ecmaVersion: 11,
sourceType: 'module',
tsconfigRootDir: __dirname,
},
plugins: ['@typescript-eslint'],
rules: {
indent: ['warn', 4],
indent: 'off',
'max-len': 'off',
},
overrides: [
{
files: ['*.ts', '*.tsx'], // Your TypeScript files extension
parserOptions: {
project: ['./tsconfig.json'], // Specify it only for TypeScript files
},
},
],
};
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ $ yarn add affiliate
Or use a CDN ([check out the codeless setup](#blogs-and-related-sites))

```html
<!-- Replace 3.0.0 with your intended version -->
<script src="https://cdn.jsdelivr.net/npm/affiliate@3.0.0/dist/affiliate.js"></script>
<script src="https://cdn.jsdelivr.net/npm/affiliate@4/dist/web/affiliate.web.js"></script>
```

## What It Can Do
Expand All @@ -43,7 +42,8 @@ Affiliate has easy [plugins](https://affiliate.js.org/plugins), including one fo
Read **[the documentation](https://affiliate.js.org/)** for more advanced usage.

```js
const Affiliate = require('affiliate');
import Affiliate from 'affiliate';

const aff = Affiliate.create({
tags: [
{
Expand All @@ -60,40 +60,40 @@ const aff = Affiliate.create({
},
],
});

aff.attach();
```

## Documentation

Affiliate is simple and quick to set up, even for more complex usage. Read the docs at: **[affiliate.js.org](https://affiliate.js.org/)**.

### Blogs and Related Sites
## Blogs and Related Sites

A simplified codeless solution might better suit some blogging-style sites.
A simplified codeless solution might better suit some sites that use content module systems, such as WordPress, SquareSpace, etc.

Insert this code within the HTML `<head>...</head>` tag. The contents of the `data-aff` attribute will tell Affiliate what to do.
Insert this code within the HTML `<head>...</head>` tag. The contents of the `data-auto-affiliate` attribute will tell Affiliate what to do.

```html
<!-- Replace 2.0 with your intended version -->
<script
data-aff="amazon.com, www.amazon.com : tag = MY-AMAZON-TAG"
src="https://cdn.jsdelivr.net/npm/affiliate@3.0/dist/affiliate.js"
data-auto-affiliate="WHERE amazon.com, www.amazon.com SET tag = MY-AMAZON-TAG"
src="https://cdn.jsdelivr.net/npm/affiliate@4/dist/web/affiliate.web.js"
async
id="aff-js"
></script>
```

#### data-aff Syntax
### data-auto-affiliate Syntax

The syntax for data-aff is a comma separated list of domains, a colon, and then comma separated list of url queries in the format `key=value`. Multiple website groups can be separated by an exclamation mark.
The syntax for data-auto-affiliate is capital `WHERE`, a comma separated list of domains, capital `SET`, and then comma separated list of URL queries in the format `key=value`. Multiple website groups can be separated by a capital `AND`.

```
amazon.com, www.amazon.com : tag = MY-AMAZON-TAG ! example.com, shop.example.com : ref = MY-OTHER-TAG
```sql
WHERE amazon.com, www.amazon.com SET tag = MY-AMAZON-TAG AND WHERE example.com, shop.example.com SET ref = MY-OTHER-TAG
```

## Left with Questions?

If for any reason you feel that this documentation is unclear or incomplete, [add an issue](https://github.com/russellsteadman/affiliate/issues/new) detailing what needs to be improved. It will be addressed quickly.
If for any reason you feel that this documentation is unclear or incomplete, [add an issue](https://github.com/russellsteadman/affiliate/issues/new) detailing what needs to be improved.

## Star This Project

Expand Down
11 changes: 5 additions & 6 deletions dist/node/Affiliate.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import URLParse from 'url-parse';
import Log from './shared/log';
export interface AffiliateConfigTag {
hosts: string | string[];
Expand All @@ -9,7 +8,7 @@ export interface AffiliateConfigTag {
to: string;
from: string;
}[];
modify?: (url: URLParse) => URLParse | string;
modify?: (url: URL) => URL | string;
}
export interface AffiliateConfig {
tags: AffiliateConfigTag[];
Expand All @@ -33,7 +32,7 @@ declare class Affiliate {
* @function
* @param {object=} nodeSet The node to traverse for links (default: document.body)
*/
traverse(nodeSet?: HTMLElement): void;
traverse(nodeSet?: HTMLElement): Affiliate;
/**
* Modify the URL of a matching link while preserving the original link state
*
Expand All @@ -43,18 +42,18 @@ declare class Affiliate {
* @param {object} node Anchor link node
* @param {object} tag Matching configuration tag
*/
modifyURL: (url: URLParse, node: HTMLAnchorElement, tag: AffiliateConfigTag) => void;
modifyURL: (url: URL, node: HTMLAnchorElement, tag: AffiliateConfigTag) => void;
/**
* Attach the mutation observer
*
* @function
*/
attach: () => void;
attach: () => Affiliate;
/**
* Detach the mutation observer
*
* @function
*/
detach: () => void;
detach: () => Affiliate;
}
export default Affiliate;
96 changes: 53 additions & 43 deletions dist/node/Affiliate.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit dd19d6a

Please sign in to comment.