mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-21 17:38:40 +00:00
配置文件区分版本,增加关闭一段时间再显示的逻辑
This commit is contained in:
parent
033fa1da1f
commit
7d4197aca5
@ -1,13 +1,13 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="ad" v-show="ads.length && isShow" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
|
<div class="ad" v-show="ads.length && isShow">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
<div class="title">Creator插件推荐</div>
|
<div class="title">Creator Plugin Recommendation</div>
|
||||||
<div style="flex: 1"></div>
|
<div style="flex: 1"></div>
|
||||||
<div class="close" @click="onClose">
|
<div class="close" @click="onClose" :title="closeTitle">
|
||||||
<i class="icon iconfont icon_close"></i>
|
<i class="icon iconfont icon_close"></i>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="body">
|
<div class="body" @mouseenter="onMouseEnter" @mouseleave="onMouseLeave">
|
||||||
<div class="left slide" @click="onClickBtnLeft">
|
<div class="left slide" @click="onClickBtnLeft">
|
||||||
<i class="iconfont icon_arrow_left arrow"></i>
|
<i class="iconfont icon_arrow_left arrow"></i>
|
||||||
</div>
|
</div>
|
||||||
@ -21,18 +21,21 @@
|
|||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { defineComponent, onMounted, ref, toRaw } from "vue";
|
import { defineComponent, onMounted, onUnmounted, ref, toRaw } from "vue";
|
||||||
|
import { GA_EventName } from "../../ga/type";
|
||||||
import Banner from "./banner.vue";
|
import Banner from "./banner.vue";
|
||||||
import { emitter, Msg } from "./const";
|
import { emitter, Msg } from "./const";
|
||||||
import { AdItem, getAdData } from "./loader";
|
import { AdItem, getAdData } from "./loader";
|
||||||
import { ga } from "./util";
|
import { ga } from "./util";
|
||||||
import { GA_EventName } from "../../ga/type";
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
name: "ad",
|
name: "ad",
|
||||||
components: { Banner },
|
components: { Banner },
|
||||||
setup() {
|
setup() {
|
||||||
let ads = ref<AdItem[]>([]);
|
let ads = ref<AdItem[]>([]);
|
||||||
let stopAutoScroll = false;
|
let stopAutoScroll = false;
|
||||||
|
const key = "close-time";
|
||||||
|
let timer = null;
|
||||||
|
const closeTitle = ref("");
|
||||||
onMounted(async () => {
|
onMounted(async () => {
|
||||||
const data = await getAdData();
|
const data = await getAdData();
|
||||||
if (!data) {
|
if (!data) {
|
||||||
@ -49,8 +52,13 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
ads.value = data.data;
|
ads.value = data.data;
|
||||||
console.log("get ads ", toRaw(ads.value));
|
console.log("get ads ", toRaw(ads.value));
|
||||||
|
closeTitle.value = `display again in ${data.showDuration} minute`;
|
||||||
|
|
||||||
setInterval(() => {
|
visibleAd(data.showDuration);
|
||||||
|
adScroll(data.scrollDuration);
|
||||||
|
});
|
||||||
|
function adScroll(scrollDuration: number) {
|
||||||
|
timer = setInterval(() => {
|
||||||
// return;
|
// return;
|
||||||
if (stopAutoScroll) {
|
if (stopAutoScroll) {
|
||||||
return;
|
return;
|
||||||
@ -64,9 +72,19 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
el.scrollTo({ left, behavior: "smooth" });
|
el.scrollTo({ left, behavior: "smooth" });
|
||||||
}
|
}
|
||||||
}, data.scrollDuration * 1000);
|
}, scrollDuration * 1000);
|
||||||
|
}
|
||||||
|
function visibleAd(showDuration: number) {
|
||||||
|
const time = Number(localStorage.getItem(key) || "0");
|
||||||
|
if (time) {
|
||||||
|
// 单位分钟
|
||||||
|
const diff = (Date.now() - time) / 1000 / 60;
|
||||||
|
isShow.value = diff >= showDuration;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onUnmounted(() => {
|
||||||
|
clearInterval(timer);
|
||||||
});
|
});
|
||||||
|
|
||||||
function testBanner() {
|
function testBanner() {
|
||||||
const data = new AdItem();
|
const data = new AdItem();
|
||||||
data.name = "ad test 11111111111 11111111111 44444444444444 5555555555555 111111111111111111 2222222222222222 33333333333333 444444444444444";
|
data.name = "ad test 11111111111 11111111111 44444444444444 5555555555555 111111111111111111 2222222222222222 33333333333333 444444444444444";
|
||||||
@ -77,11 +95,13 @@ export default defineComponent({
|
|||||||
const adWidth = 300;
|
const adWidth = 300;
|
||||||
const isShow = ref(true);
|
const isShow = ref(true);
|
||||||
return {
|
return {
|
||||||
|
closeTitle,
|
||||||
isShow,
|
isShow,
|
||||||
elAd,
|
elAd,
|
||||||
ads,
|
ads,
|
||||||
onClose() {
|
onClose() {
|
||||||
isShow.value = false;
|
isShow.value = false;
|
||||||
|
localStorage.setItem(key, Date.now().toString());
|
||||||
ga(GA_EventName.CloseAd);
|
ga(GA_EventName.CloseAd);
|
||||||
},
|
},
|
||||||
onMouseEnter() {
|
onMouseEnter() {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
|
import CCPlugin from "../../../cc-plugin.config";
|
||||||
import { githubMirrorMgr } from "./github";
|
import { githubMirrorMgr } from "./github";
|
||||||
|
|
||||||
export class AdItem {
|
export class AdItem {
|
||||||
/**
|
/**
|
||||||
* 广告的名字
|
* 广告的名字
|
||||||
@ -43,7 +43,6 @@ export class AdItem {
|
|||||||
}
|
}
|
||||||
export class AdData {
|
export class AdData {
|
||||||
desc: string = "";
|
desc: string = "";
|
||||||
version: string = "";
|
|
||||||
/**
|
/**
|
||||||
* 是否启用广告
|
* 是否启用广告
|
||||||
*/
|
*/
|
||||||
@ -68,7 +67,6 @@ export class AdData {
|
|||||||
data: Array<AdItem> = [];
|
data: Array<AdItem> = [];
|
||||||
parse(data: AdData) {
|
parse(data: AdData) {
|
||||||
this.desc = data.desc;
|
this.desc = data.desc;
|
||||||
this.version = data.version;
|
|
||||||
this.valid = !!data.valid;
|
this.valid = !!data.valid;
|
||||||
this.showDuration = data.showDuration || 10;
|
this.showDuration = data.showDuration || 10;
|
||||||
this.scrollDuration = data.scrollDuration || 3;
|
this.scrollDuration = data.scrollDuration || 3;
|
||||||
@ -99,7 +97,7 @@ export class AdData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export async function getAdData(): Promise<AdData | null> {
|
export async function getAdData(): Promise<AdData | null> {
|
||||||
const data = await githubMirrorMgr.getData("ad.json");
|
const data = await githubMirrorMgr.getData(`ad-${CCPlugin.manifest.version}.json`);
|
||||||
if (data) {
|
if (data) {
|
||||||
const ad = new AdData();
|
const ad = new AdData();
|
||||||
ad.parse(data as AdData);
|
ad.parse(data as AdData);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user