GoAlimama

自动跳转到商品相应的淘宝客页面,自己的返利自己赚!

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         GoAlimama
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  自动跳转到商品相应的淘宝客页面,自己的返利自己赚!
// @author       Neo
// @include http*://item.taobao.com/*
// @include http*://detail.tmall.com/*
// @grant        none
// ==/UserScript==

// Your code here...
//debugger;
function run(){
	var searchPrefix="http://pub.alimama.com/promo/search/index.htm?q=";
	var link=location.href;
	var realLink=getRealLink(link);
	console.log(realLink);
	var isTb=location.host==='item.taobao.com';
	var isTm=location.host==='detail.tmall.com';
	var targetLink=searchPrefix+encodeURIComponent(realLink);
	var block;
	if(isTm){
		block=document.querySelector('.tb-key');
	}
	else{
		block=document.querySelector('.tb-item-info-r');
	}
	var br=document.createElement('br');
	var mamaLink=document.createElement('a');
	mamaLink.href=targetLink;
	mamaLink.target='_blank';
	mamaLink.innerText='ALIMAMA';
	block.appendChild(mamaLink);
}

function getRealLink(longLink){
	var n=longLink.indexOf('?');
	if (n>0) {
		var params=longLink.substr(n+1).split('&');
		for (var i in params){
			var param=params[i];
			if (param.indexOf('id=')===0) {
				return longLink.substr(0,n+1)+param;
			}
		}
	}
}
run();