-
Notifications
You must be signed in to change notification settings - Fork 13
/
store product detail title text to link.html
109 lines (58 loc) · 2.49 KB
/
store product detail title text to link.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
103
104
105
106
107
108
109
<script>
$( ( ) => {
/*
store product detail title text to link
License : < https://tinyurl.com/s872fb68 >
Version : 0.1.0
SS Version : 7.1
Fluid
Engine
Compatible : Not Applicable
Dependencies : twcsl
By : Thomas Creedon < http://www.tomsWeb.consulting/ >
*/
// initialize twc global if needed
if ( window.twc == undefined ) window.twc = { };
twc.spdtttl = {
textUrlMap : {
/*
the format of each line is text and a url
the url can be any valid url. it can be a full (external to your site)
one like < https://www.tomsWeb.consulting/ > or a partial (internal to
your site) one like '/contact'
copy and repeat the line below for each mapping, remove the "// " at
the beginning of the line and enter the appropriate data. this has
been done once initially
*/
// '[enter text here between single quotes replacing square brackets]' : '[enter url here between single quotes replacing square brackets]',
'[enter text here between single quotes replacing square brackets]' : '[enter url here between single quotes replacing square brackets]',
},
seperator : ' | ',
html : `
<br>
<a class="twc-spdtttl" href="[url]">
[text]
</a>
`,
};
// do not change anything below, there be the borg here
if ( ! twcsl.page.store.detail.is ) return; // bail if not detail
const options = twc.spdtttl;
const seperator = options.seperator;
const textUrlMap = options.textUrlMap;
let selector = '.ProductItem-details h1.ProductItem-details-title';
const $title = $( selector );
let html = $title.html ( );
const text = html
.split ( seperator )
[ 1 ]
.trim ( );
if ( ! ( text in textUrlMap ) ) return; // bail if no text
const url = textUrlMap [ text ];
options.html = options.html
.replaceAll ( '[text]', text )
.replaceAll ( '[url]', url );
html = html.replace ( `${ seperator }${ text }`, options.html );
$title.html ( html );
} );
</script>