|
1 | 1 | <template> |
2 | | - <div id="ad" :class="{ 'placement-home': placement === 'home-page' }"></div> |
| 2 | + <div v-if="!hasError" id="ad" :class="{ 'placement-home': placement === 'home-page' }"></div> |
| 3 | + <div v-else id="ad" class="error"> |
| 4 | + <div class="p-4 flex flex-col"> |
| 5 | + <span class="font-bold font-display">🙏 Enable Ads</span> |
| 6 | + <span class="mt-2"> Please enable ads on your browser for this website. </span> |
| 7 | + <span class="mt-1"> Ads are a funding source to this project. </span> |
| 8 | + |
| 9 | + <div class="mt-2 or-fund-it"> |
| 10 | + <span class="mx-1 whitespace-nowrap">or consider</span> |
| 11 | + </div> |
| 12 | + |
| 13 | + <a |
| 14 | + target="_blank" |
| 15 | + rel="noopener" |
| 16 | + href="https://github.com/sponsors/logaretm" |
| 17 | + class="mt-2 bg-pink-600 py-1 px-2 text-white font-medium flex items-center justify-center font-display rounded group hover:bg-pink-700" |
| 18 | + > |
| 19 | + <svg |
| 20 | + class="stroke-current transform transition duration-200 group-hover:scale-110 w-5 h-5 mr-1" |
| 21 | + fill="none" |
| 22 | + viewBox="0 0 24 24" |
| 23 | + xmlns="http://www.w3.org/2000/svg" |
| 24 | + > |
| 25 | + <path |
| 26 | + stroke-linecap="round" |
| 27 | + stroke-linejoin="round" |
| 28 | + stroke-width="2" |
| 29 | + d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z" |
| 30 | + ></path> |
| 31 | + </svg> |
| 32 | + |
| 33 | + Sponsor |
| 34 | + </a> |
| 35 | + </div> |
| 36 | + </div> |
3 | 37 | </template> |
4 | 38 |
|
5 | 39 | <script setup lang="ts"> |
6 | | -import { onMounted } from 'vue'; |
| 40 | +import { onMounted, ref } from 'vue'; |
7 | 41 |
|
8 | 42 | defineProps<{ |
9 | 43 | placement?: 'content' | 'home-page'; |
10 | 44 | }>(); |
11 | 45 |
|
| 46 | +const hasError = ref(false); |
| 47 | +
|
12 | 48 | function loadScript() { |
13 | 49 | const script = document.createElement('script'); |
14 | 50 | script.src = '//cdn.carbonads.com/carbon.js?serve=CE7DKKQ7&placement=vee-validatelogaretmcom'; |
15 | 51 | script.id = '_carbonads_js'; |
16 | 52 |
|
17 | 53 | const el = document.querySelector('#ad'); |
18 | 54 | el?.appendChild(script); |
| 55 | + script.onerror = error => { |
| 56 | + if (navigator.onLine) { |
| 57 | + hasError.value = true; |
| 58 | + } |
| 59 | + }; |
19 | 60 | } |
20 | 61 |
|
21 | 62 | onMounted(loadScript); |
@@ -122,6 +163,22 @@ onMounted(loadScript); |
122 | 163 | #carbonads { |
123 | 164 | @apply bg-zinc-800; |
124 | 165 | } |
| 166 | +
|
| 167 | + &.error { |
| 168 | + @apply bg-zinc-800; |
| 169 | + } |
| 170 | + } |
| 171 | +} |
| 172 | +
|
| 173 | +.or-fund-it { |
| 174 | + @apply text-zinc-500 flex items-center space-x-2; |
| 175 | +
|
| 176 | + &::before, |
| 177 | + &::after { |
| 178 | + height: 1px; |
| 179 | + width: 100%; |
| 180 | + content: ''; |
| 181 | + @apply flex-shrink bg-zinc-500; |
125 | 182 | } |
126 | 183 | } |
127 | 184 | </style> |
0 commit comments