This repository has been archived by the owner on Aug 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
102 lines (80 loc) · 4.09 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!DOCTYPE html>
<html>
<body>
<!-- Convert the following JavaScript code to a HTML code, for example:
<script type="text/javascript"> amzn_assoc_placement = "adunit0"; amzn_assoc_search_bar = "true"; amzn_assoc_tracking_id = "cfky05-20"; amzn_assoc_ad_mode = "manual"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "US"; amzn_assoc_title = "About Hans Selye"; amzn_assoc_linkid = "a79c4f73a9592cb7ac406607107a58f7"; amzn_assoc_asins = "B00IHGCNUO,B00IHGCONU,0805073698,0070562121"; </script>
<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"></script>
-----------------------------------------
<div class="amznads" data-amznads='amzn_assoc_placement = "adunit0"; amzn_assoc_search_bar = "false"; amzn_assoc_tracking_id = "cfky05-20"; amzn_assoc_ad_mode = "manual"; amzn_assoc_ad_type = "smart"; amzn_assoc_marketplace = "amazon"; amzn_assoc_region = "US"; amzn_assoc_title = "Hans Selye Picks"; amzn_assoc_linkid = "0816b1d20c9c0a26f0f1f662e8a9228f"; amzn_assoc_asins = "B00IHGCNUO,B00IHGCONU,0805073698,0070562121";'></div>
-->
<div class="header">
<h1>Amazon Associates Ads Loader for Tumblr</h1>
<p>A tool to convert the Amazon Associate JavaScript Ads code to a HTML format. (<a href="https://github.com/chriskyfung/amzn_assoc_loader_for_tumblr" target="_blank">Help</a>)</p>
<div>
<hr>
<div>
<label for="input">Paste your Amazone Ad Code to here<br></label>
<textarea name="input" id="js-ad-code" rows="20" cols="80"></textarea><br>
<button type="button" onclick="convertAdCode()">Convert</button>
<br>
<label for="output">Copy and paste to your Tumblr post<br></label>
<textarea name="output" id="html-ad-code" rows="10" cols="80"></textarea><br>
</div>
<script>
function convertAdCode(){
/* Get the text field */
var inputarea = document.getElementById("js-ad-code");
var outputarea = document.getElementById("html-ad-code");
var textvalue = inputarea.value.slice(0);
/* Texts to format */
var prefix = "<script type='text/javascript'>";
var suffix = "<script src='\/\/z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US'><\/script>";
if (textvalue === "") {
outputarea.value = "No string!"
}
else if (textvalue.replace(/"/g, "'").startsWith(prefix)) {
outputarea.value = textvalue.replace(/"/g, "'").replace(prefix, "<div class=\"amznads\" data-amznads=\"").replace(suffix, "<\/div>").replace("<\/script>", "\">").replace(/\r?\n|\r/g, "");
/* Select the text field */
outputarea.select();
/* Copy the text inside the text field */
document.execCommand("copy");
/* Alert the copied text */
alert("Copied the text: " + outputarea.value);
document.getElementById("loadbutton").style.display = "block";
}
};
</script>
<input id="loadbutton" type="button" onclick="loadAmazonAds()" value="Load the Ads" style="display:none;"/>
<div id="wrapper"></div>
<script>
/* Load Amazon Ads Widget */
function loadAmazonAds(){
var outputarea = document.getElementById("html-ad-code");
var wrapper = document.getElementById("wrapper");
wrapper.innerHTML = outputarea.value;
var s2 = '<script src="//z-na.amazon-adsystem.com/widgets/onejs?MarketPlace=US"><\/script>';
var x = document.getElementsByClassName('amznads');
var i;
for (i = 0; i < x.length; i++) {
var data = x[i].getAttribute("data-amznads");
var s1 = '<script type="text/javascript"> ' + data + '<\/script>';
x[i].setAttribute('id', 'amznad1_' + i);
document.write('<div id="amznad0_' + i + '">' + s1 + s2 + '</div>');
}
}
function MoveDiv() {
var fragment = document.createDocumentFragment();
fragment.appendChild(document.getElementById('amznad0_0'));
document.getElementById('amznad1_0').appendChild(fragment);
}
</script>
<!-- Global site tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-72575541-9"></script>
<script>
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', 'UA-72575541-9');
</script>
</body>
</html>