Skip to content

Commit 6bdab60

Browse files
authored
Merge pull request #2 from coderberry/berry/feature/upgrade-to-codefund-2.0
Patch for compatibility with CodeFund v2.0 (codefund.app)
2 parents e41a07b + be55484 commit 6bdab60

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# docsify-plugin-codefund
2-
a plugin to make you easy to join up [codefund](https://codesponsor.io/)
2+
a plugin to make you easy to join up [CodeFund](https://codefund.app/)
33

44
# Usage
55
```
@@ -17,7 +17,7 @@ window.$docsify = {
1717
search: 'auto', // default,
1818
1919
plugins: [
20-
DocsifyCodefund.create('51d43327-eea3-4e27-bd44-e075e67a84fb') // change to your codefund id
20+
DocsifyCodefund.create(15) // change to your CodeFund property id
2121
]
2222
```
2323

index.js

Lines changed: 19 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,28 @@
33
create: function(codefundId) {
44
return function(hook, vm) {
55
hook.ready(function() {
6-
var style = document.createElement('style')
7-
var css = '#codefund_ad span.cf-wrapper { background-color: rgba(0,0,0,0) } #codefund_ad a.cf-text { color: #444; font-weight: 400; font-size: 10px }'
8-
9-
style.type = 'text/css'
10-
if (style.styleSheet){
11-
style.styleSheet.cssText = css
12-
} else {
13-
style.appendChild(document.createTextNode(css))
14-
}
15-
document.head.appendChild(style)
16-
17-
var script = document.createElement('script')
18-
script.src = "https://codefund.io/scripts/" + codefundId + "/embed.js"
19-
document.body.appendChild(script)
6+
window.DocsifyCodefund.injectCodeFundContainer();
7+
window.DocsifyCodefund.injectCodeFundScript(codefundId);
208
})
9+
}
10+
},
2111

22-
hook.doneEach(function () {
23-
// create a codefun container
24-
let nav = document.getElementsByClassName('sidebar-nav')
25-
let codefunContainer = document.createElement('div')
26-
codefunContainer.id = 'codefund_ad'
27-
nav[0].insertBefore(codefunContainer, nav[0].firstChild)
12+
injectCodeFundContainer() {
13+
let nav = document.getElementsByClassName('sidebar-nav')
14+
let codefundContainer = document.createElement('div')
15+
codefundContainer.id = 'codefund'
16+
nav[0].insertBefore(codefundContainer, nav[0].firstChild)
2817

29-
if (document.getElementsByClassName('cf-wrapper').length === 0) {
30-
window._codefund && window._codefund.serve();
31-
}
32-
})
18+
if (document.getElementsByClassName('cf-wrapper').length === 0) {
19+
window._codefund && window._codefund.serve();
3320
}
21+
},
22+
23+
injectCodeFundScript(codefundId) {
24+
var script = document.createElement('script')
25+
script.src = "https://codefund.app/properties/" + codefundId + "/funder.js?template=docsify"
26+
script.async = "async"
27+
document.body.appendChild(script)
3428
}
3529
}
36-
})(window)
30+
})(window)

0 commit comments

Comments
 (0)