Skip to content

Commit

Permalink
Plugin v2.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
russellsteadman committed Jul 4, 2018
1 parent a9fadba commit f659c69
Show file tree
Hide file tree
Showing 16 changed files with 1,899 additions and 2,224 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ node_modules/
yarn.lock
test/
webpack.config.js
webpack.config.node.js
.babelrc
docs/
13 changes: 3 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,6 @@ This plugin for the open source [Affiliate package](https://github.com/teamtofu/
```bash
$ npm i -S affiliate affiliate-plugin-amazon
$ yarn add affiliate affiliate-plugin-amazon
$ bower install -S affiliate affiliate-plugin-amazon
```

Or use a CDN
```html
<script src="https://cdn.jsdelivr.net/npm/affiliate/dist/affiliate.js"></script>
<script src="https://cdn.jsdelivr.net/npm/affiliate-plugin-amazon/dist/plugin.js"></script>
```

## What It Can Do
Expand All @@ -25,7 +18,7 @@ Affiliate can modify the following link into any of the others.
<a href="https://www.amazon.co.uk/dp/B01MRZFBBH">UK</a>
```

All links would become (if the user's primary language is Italian):
If the user's primary language is Italian, all links would become:
```html
<a href="https://www.amazon.it/dp/B01MRZFBBH?tag=italian-tag">My Locality</a>
```
Expand All @@ -52,8 +45,8 @@ Cross-browser Testing Platform and Open Source <3 Provided by [Sauce Labs](https

## License

MIT (C) [Russell Steadman](https://teamtofu.github.io/contact). Learn more in the [LICENSE](https://github.com/teamtofu/affiliate-plugin-amazon/blob/master/LICENSE) file.
MIT (C) [Russell Steadman](https://teamtofu.github.io/contact/). Learn more in the [LICENSE](https://github.com/teamtofu/affiliate-plugin-amazon/blob/master/LICENSE) file.

## Support Me

Like this project? Buy me a [cup of coffee](https://www.paypal.me/RussellSteadman/3). &#x2615; Here are more of my [projects](https://teamtofu.github.io/).
Like this project? Buy me a [cup of coffee](https://www.paypal.me/RussellSteadman/3) or [contribute](https://github.com/teamtofu/affiliate-plugin-amazon). &#x2615; Here are more of my [projects](https://teamtofu.github.io/).
2 changes: 1 addition & 1 deletion dist/plugin.js

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

1 change: 1 addition & 0 deletions dist/plugin.node.js

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

2 changes: 1 addition & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1 @@
module.exports = require('./src');
module.exports = require('./dist/plugin.node');
20 changes: 11 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "affiliate-plugin-amazon",
"version": "1.1.1",
"version": "2.0.0",
"description": "A plugin for the \"affiliate\" package that works with Amazon links",
"main": "index.js",
"repository": "https://github.com/teamtofu/affiliate-plugin-amazon.git",
Expand All @@ -13,15 +13,17 @@
},
"private": false,
"devDependencies": {
"affiliate": "^1.2.1",
"babel-core": "^6.26.0",
"babel-loader": "^7.1.2",
"babel-preset-env": "^1.6.1",
"uglifyjs-webpack-plugin": "^1.1.5",
"webpack": "^3.10.0"
"affiliate": "^2.0.0",
"babel-core": "^6.26.3",
"babel-loader": "^7.1.4",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"babel-preset-env": "^1.7.0",
"uglifyjs-webpack-plugin": "^1.2.7",
"webpack": "^4.14.0",
"webpack-command": "^0.4.0"
},
"peerDependencies": {
"affiliate": "^1.2.1"
"affiliate": "^2.0.0"
},
"keywords": [
"affiliate",
Expand All @@ -37,7 +39,7 @@
"advertisement"
],
"scripts": {
"build": "webpack && webpack --config test/webpack/webpack.config.js",
"build": "webpack && webpack --config webpack.config.node.js && webpack --config test/webpack/webpack.config.js",
"test-cred": "sh ./test/sauce/cred.sh",
"test": "sh ./test/sauce/run.sh",
"test-webpack": "sh ./test/sauce/run-webpack.sh"
Expand Down
71 changes: 0 additions & 71 deletions src/extend.js

This file was deleted.

51 changes: 24 additions & 27 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
var extend = require('./extend');
const projectSite = 'https://affiliate.js.org/plugins/amazon';

var projectSite = 'https://affiliate.js.org/plugins/amazon';

var log = function (isError) {
const log = function (isError) {
if (typeof console === 'object') {
var args = Array.prototype.slice.call(arguments, 1);
var logFunc = isError ? console.error : console.log;
Expand All @@ -11,9 +9,8 @@ var log = function (isError) {
}
};

var Plugin = function (Affiliate, config) {

var basic = {
const Plugin = (Affiliate, config) => {
let basic = {
tags: {
us: '',
gb: '',
Expand All @@ -33,11 +30,13 @@ var Plugin = function (Affiliate, config) {
modifyDomain: true
};

config = extend(basic, config);
if (config && config.tags) config.tags = {...basic.tags, ...config.tags};
config = {...basic, ...config};

if (config.debug) log(false, 'Read the docs at ' + projectSite);
if (!config.tags.us) return log(true, 'Config must contain a US tag.');

var tagList = {
let tagList = {
us: {
tld: 'com',
la: ['en']
Expand Down Expand Up @@ -88,19 +87,16 @@ var Plugin = function (Affiliate, config) {
}
};

for (var i in tagList) {
var domain = 'amazon.' + tagList[i].tld;
for (let i in tagList) {
let domain = 'amazon.' + tagList[i].tld;
tagList[i].hosts = [domain, 'www.' + domain];
}

if (!config.locale) {
var languages = window.navigator.languages.reduce(function (a, b) {
a.push(b.toLowerCase());
return a;
}, []);
for (var i in languages) {
var cc = languages[i].split('-')[1];
for (var o in tagList) {
let languages = window.navigator.languages.map((a) => (a.toLowerCase()));
for (let i in languages) {
let cc = languages[i].split('-')[1];
for (let o in tagList) {
if (o === cc || tagList[o].la.indexOf(languages[i]) !== -1) {
config.locale = o;
break;
Expand All @@ -115,22 +111,23 @@ var Plugin = function (Affiliate, config) {
if (!config.tags[config.locale]) config.locale = 'us';
if (config.debug) log(false, 'Locale set to "' + config.locale + '".');

var hosts = [];
for (var i in tagList) {
let hosts = [];
for (let i in tagList) {
hosts = hosts.concat(tagList[i].hosts);
}

var affSettings = {
let affSettings = {
tags: [
{
hosts: hosts,
query: {
tag: config.tags[config.locale]
},
modifyHost: function (host) {
var hasWWW = 0;
if (host.substr(0, 3) === 'www') hasWWW = 1;
return tagList[config.locale].hosts[hasWWW];
modify: (url) => {
let hasWWW = 0;
if (url.hostname.substr(0, 3) === 'www') hasWWW = 1;
url.set('hostname', tagList[config.locale].hosts[hasWWW]);
return url;
}
}
],
Expand All @@ -139,8 +136,8 @@ var Plugin = function (Affiliate, config) {

if (config.modifyDomain === false) {
affSettings.tags = [];
for (var i in config.tags) {
if (tagList[i]) {
for (let i in config.tags) {
if (tagList[i] && config.tags[i]) {
affSettings.tags.push({
hosts: tagList[i].hosts,
query: {
Expand Down
Loading

0 comments on commit f659c69

Please sign in to comment.