Skip to content

Commit 8bd5ac2

Browse files
committed
Merge branch 'fix/ads-load' into develop
2 parents e2c48c7 + 50b671c commit 8bd5ac2

3 files changed

Lines changed: 70 additions & 24 deletions

File tree

public/carbon.js

Lines changed: 0 additions & 1 deletion
This file was deleted.

public/manifest.json

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,22 @@
11
{
22
"name": "Hackertab.dev",
33
"description": "The Developer’s Homepage",
4-
"version": "1.12.1",
4+
"version": "1.12.4",
55
"manifest_version": 2,
66
"chrome_url_overrides": {
77
"newtab": "index.html"
88
},
99
"background": {
10-
"scripts": [
11-
"background.js"
12-
]
10+
"scripts": ["background.js"]
1311
},
14-
"permissions": [
15-
"https://*.hackertab.dev/*"
16-
],
12+
"permissions": ["https://*.hackertab.dev/*"],
1713
"icons": {
1814
"16": "/logos/logo16.png",
1915
"32": "/logos/logo32.png",
2016
"48": "/logos/logo48.png",
2117
"128": "/logos/logo128.png"
2218
},
23-
"content_security_policy": "script-src 'self' https://*.carbonads.com https://*.buysellads.net https://*.buysellads.com https://*.servedby-buysellads.com https://*.carbonads.net; object-src 'self'",
19+
"content_security_policy": "script-src 'self' object-src 'self'",
2420
"applications": {
2521
"gecko": {
2622
"id": "{f8793186-e9da-4332-aa1e-dc3d9f7bb04c}"

src/components/CarbonAd.js

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,71 @@
1-
import React, { Component } from 'react';
2-
import './CarbonAd.css';
1+
import axios from 'axios'
2+
import React, { useEffect, useState } from 'react'
3+
import './CarbonAd.css'
34

4-
class CarbonAd extends Component {
5-
componentDidMount() {
6-
const carbon_wrapper = document.querySelector('.carbon-ad-wrapper')
7-
const script = document.createElement('script')
8-
script.src = process.env.PUBLIC_URL + '/carbon.js?serve=CESDP23I&placement=hackertabdev'
9-
script.async = true
10-
script.id = '_carbonads_js'
5+
export default function CarbonAd() {
6+
const [ad, setAd] = useState()
7+
const packageFile = require('../../package.json')
118

12-
carbon_wrapper.appendChild(script)
13-
}
9+
useEffect(() => {
10+
const setup = async () => {
11+
const userAgent = new URLSearchParams(navigator.userAgent).toString()
12+
var baseUrl = process.env.NODE_ENV === 'production' ? packageFile.proxy : ''
13+
const request = await axios.get(`${baseUrl}/monetization/?useragent=${userAgent}`)
14+
if (request.data) {
15+
setAd(request.data.ads[0])
16+
}
17+
}
18+
setup()
19+
}, [])
1420

15-
render() {
16-
return <div className="carbon-ad-wrapper blockRow" />
21+
const prependHTTP = (url) => {
22+
url = decodeURIComponent(url)
23+
if (!/^(?:f|ht)tps?\:\/\//.test(url)) {
24+
url = 'https://' + url
25+
}
26+
return url
1727
}
18-
}
1928

20-
export default CarbonAd;
29+
return (
30+
<div className="carbon-ad-wrapper blockRow">
31+
{ad && (
32+
<div id="carbonads">
33+
<span>
34+
<span className="carbon-wrap">
35+
<a
36+
href={prependHTTP(ad.statlink)}
37+
className="carbon-img"
38+
target="_blank"
39+
rel="noopener sponsored"
40+
title={ad.company + ' ' + ad.companyTagline}>
41+
<img
42+
src={ad.smallImage}
43+
border="0"
44+
height="100"
45+
width="130"
46+
style={{ background: ad.backgroundColor }}
47+
/>
48+
</a>
49+
50+
<a
51+
href={prependHTTP(ad.statlink)}
52+
className="carbon-text"
53+
target="_blank"
54+
rel="noopener sponsored">
55+
{ad.description}
56+
</a>
57+
</span>
58+
59+
<a
60+
href={ad.ad_via_link}
61+
className="carbon-poweredby"
62+
target="_blank"
63+
rel="noopener sponsored">
64+
ads via Carbon
65+
</a>
66+
</span>
67+
</div>
68+
)}
69+
</div>
70+
)
71+
}

0 commit comments

Comments
 (0)