summaryrefslogtreecommitdiff
path: root/static/js/adblockbar.js
blob: ee8031ff3ae81b3b907a535298ca5498eb7cb899 (plain)
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
/*
 * Originally made by an anonymous netizen: https://adblockbar.neocities.org/
 * Modified by yours truly: https://rayhammer.dev/
 */
var AdBlockBar = function() {
    this.installed = true
    this.displayOnce = true
  
    this.appUrls = {
      "iPrison": "http://adblockios.com/",
      "adSkynet5000": "https://adblockplus.org/",
      "aRealComputer": "https://github.com/gorhill/uBlock"
    }
  
    this.localStorageId = '__adblockbar_shown'
  
    if(navigator.userAgent.match(/(iPad|iPhone|iPod)/g))
      this.platform = 'iPrison'
    else if(navigator.userAgent.match(/Android/i))
      this.platform = 'adSkynet5000'
    else
      this.platform = 'aRealComputer'
  
    this.detect = function() {
      var bait = document.createElement('img')
      bait.onerror = function() {
        //this.parentNode.removeChild(this)
      }
      bait.id = '__adblockbar_bait'
      bait.style['position'] = 'absolute'
      bait.style['left'] = '-999em'
      bait.src = 'ad1.jpg'
  
      document.getElementsByTagName('body')[0].insertBefore(bait, document.getElementsByTagName('body')[0].firstChild)
  
      var self = this
      setTimeout(function() {
        if(!bait || bait.style.display != 'none')
          self.display()
      }, 200)
    }
  
    this.display = function() {
      if(this.displayOnce === true && localStorage.getItem(this.localStorageId) == 'true')
        return
  
      if(this.displayOnce === true)
        localStorage.setItem(this.localStorageId, 'true')
  
      var html = '<div id="'+this.bannerId+'" style="position: fixed; left: 0px; border-bottom: 1px solid #DFDDCB; top: 0px; margin: 0px; width: 100%; z-index: 99999; color: rgb(111, 109, 91); font-size: 10pt; padding: 0px; background: none repeat scroll 0% 0% rgb(255, 252, 223); text-align: left;"><a href="'+this.appUrls[this.platform]+'" style="color: rgb(79, 77, 59); text-decoration: none; font: 10pt/14px &quot;Trebuchet MS&quot;,Arial,Helvetica; padding-right: 30px; display: block;" target="_blank"><span style="display: block;  color: #fff; float: left; padding: 10px 12px 10px 8px; background: #bd695b;">&#9888; Your browser is not using an ad blocker! </span><span style="display: block; padding: 10px 10px; float: left;">This makes your browser slower and hurts your privacy. For the best web experience, you should <span style="text-decoration: underline;">install an ad blocker</span>.</span></a> <a href="" style="position: absolute; text-decoration: none; width: 12px; border: medium none; padding: 3px; top: 6px; right: 14px; color: rgb(79, 77, 59); height: 14px; font: 10pt/16px &quot;Trebuchet MS&quot;,Arial,Helvetica;" onclick="this.parentNode.style.display = \'none\'; return false">&#x2716;</a></div>'
  
      var banner = document.createElement('div');
      banner.innerHTML = html;
      this.banner = banner.firstChild
  
      var body = document.getElementsByTagName('body')[0]
      body.insertBefore(this.banner, body.firstChild)
  
      //this.adjustPageMargin()
    }
  }
  
  window.onload = function() {
    var adBlockBar = new AdBlockBar()
    adBlockBar.displayOnce = false
    adBlockBar.detect()
  }