@@ -166,6 +166,12 @@ export default {
166166 return {
167167 localChecked: this .value ,
168168 connectionStatus: null ,
169+ checkIntervalId: null , // 添加变量存储定时器ID
170+ mainPostSummaryIntervalId: null , // 主贴总结按钮定时器
171+ summaryIntervalId: null , // 检查缓存和自动总结定时器
172+ allPostsSummaryIntervalId: null , // 回帖总结按钮定时器
173+ titleGenerationIntervalId: null , // 标题生成定时器
174+ observer: null ,
169175 };
170176 },
171177 watch: {
@@ -671,7 +677,8 @@ ${topic_contentdata}`;
671677 < / div>
672678 ` );
673679
674- setInterval(() => {
680+ // 将setInterval的返回值保存到data中
681+ this.checkIntervalId = setInterval(() => {
675682 if ($(".aireplay-btn").length < 1) {
676683 $("#topic-title").after(
677684 ` < button class = " aireplay-btn" type= " button" > AI 回复< / button> `
@@ -689,7 +696,7 @@ ${topic_contentdata}`;
689696
690697 // 主贴总结功能
691698 if (this.localChecked.value1) {
692- setInterval(() => {
699+ this.mainPostSummaryIntervalId = setInterval(() => {
693700 if (
694701 $(".aicreated-btn").length < 1 &&
695702 this.localChecked.btn // 只有当开启手动按钮时才显示
@@ -705,7 +712,7 @@ ${topic_contentdata}`;
705712 }
706713 }, 1000);
707714
708- setInterval(() => {
715+ this.summaryIntervalId = setInterval(() => {
709716 if ($(".post-stream").length > 0) {
710717 // 从 localStorage 获取缓存数据
711718 if ($(".gpt-summary-wrap").length < 1) {
@@ -740,7 +747,7 @@ ${topic_contentdata}`;
740747
741748 // 回帖总结功能
742749 if (this.localChecked.summaryAll) {
743- setInterval(() => {
750+ this.allPostsSummaryIntervalId = setInterval(() => {
744751 if ($(".aicreated-all-btn").length < 1) {
745752 $("#topic-title").after(
746753 ` < button class = " aicreated-all-btn" type= " button" > AI 总结全部回帖< / button> `
@@ -755,7 +762,7 @@ ${topic_contentdata}`;
755762 }
756763
757764 if (this.localChecked.title) {
758- setInterval(() => {
765+ this.titleGenerationIntervalId = setInterval(() => {
759766 if ($(".action-title").length > 0) {
760767 if ($(".action-title").html().includes("创建新话题")) {
761768 if ($(".aicreatenewtopictitle").length < 1) {
@@ -797,6 +804,42 @@ ${topic_contentdata}`;
797804 '.topic-list .main-link a.title, a[href*="/t/topic/"]',
798805 this.handleLinkClick
799806 );
807+
808+ // 清除所有定时器
809+ if (this.checkIntervalId) {
810+ clearInterval(this.checkIntervalId);
811+ }
812+ if (this.mainPostSummaryIntervalId) {
813+ clearInterval(this.mainPostSummaryIntervalId);
814+ }
815+ if (this.summaryIntervalId) {
816+ clearInterval(this.summaryIntervalId);
817+ }
818+ if (this.allPostsSummaryIntervalId) {
819+ clearInterval(this.allPostsSummaryIntervalId);
820+ }
821+ if (this.titleGenerationIntervalId) {
822+ clearInterval(this.titleGenerationIntervalId);
823+ }
824+ },
825+ // Vue 2 兼容性
826+ beforeDestroy() {
827+ // 清除所有定时器
828+ if (this.checkIntervalId) {
829+ clearInterval(this.checkIntervalId);
830+ }
831+ if (this.mainPostSummaryIntervalId) {
832+ clearInterval(this.mainPostSummaryIntervalId);
833+ }
834+ if (this.summaryIntervalId) {
835+ clearInterval(this.summaryIntervalId);
836+ }
837+ if (this.allPostsSummaryIntervalId) {
838+ clearInterval(this.allPostsSummaryIntervalId);
839+ }
840+ if (this.titleGenerationIntervalId) {
841+ clearInterval(this.titleGenerationIntervalId);
842+ }
800843 },
801844};
802845</script>
0 commit comments