PluginProbe ʕ •ᴥ•ʔ
Auto Post Cleaner / 3.3.8
Auto Post Cleaner v3.3.8
3.12.0 3.13.1 3.2.4 3.2.5 3.3.0 3.3.10 3.3.11 3.3.8 3.4.2 3.5.3 3.6.0 3.7.0 3.7.1 3.7.2 3.7.3 3.7.5 3.7.6 3.8.0 3.9.0 3.9.4 3.9.6 3.9.7 trunk 3.0.0 3.1.0 3.10.1 3.10.2 3.11.4
delete-old-posts-programmatically / assets / js / deloldp_script.js
delete-old-posts-programmatically / assets / js Last commit date
alpine.min.js 5 years ago deloldp_script.js 3 years ago
deloldp_script.js
188 lines
1 function deloldp_Start() {
2 return {
3 deloldpDays: '',
4 checkDays(days) {
5 if( days <= 7 ) {
6 var answer = confirm("Are you shure you want to delete Posts older than " + days + " days?")
7 if ( !answer ) document.getElementById("deloldpDays").value = ''
8 }
9 },
10 confirmSkipTrash() {
11 if(document.getElementById("skiptrash").checked) {
12 var answer = confirm("Are you sure you want to permanently delete the Posts? This will result in the complete deletion of the Posts without the possibility to recover them.")
13 if ( !answer ) document.getElementById("skiptrash").checked = false
14 }
15 },
16 calculateDaysInMonths(daysInMonth){
17 var daysToMonth = daysInMonth * 30
18 document.getElementById("daysInXMonths").innerHTML = daysToMonth
19 var calcDays = document.getElementById("deloldp-post-months").value;
20 if( calcDays > 0 ) document.getElementById("deloldpDays").value = calcDays * 30;
21 },
22 copyDays() {
23 var calcDays = document.getElementById("deloldp-post-months").value;
24 if( calcDays > 0 ) document.getElementById("deloldpDays").value = calcDays * 30;
25 },
26 dismiss() {
27 // Store the info dismiss status
28 localStorage.setItem("infostatus", "dismissed")
29 document.getElementById("pluginInfo").className = 'hide'
30 },
31 onstart(){
32 // get the status for info message
33 var infoStatus = localStorage.getItem("infostatus")
34 if( infoStatus == 'dismissed' ) document.getElementById("pluginInfo").classList.add("hide")
35 }
36 }
37
38 }
39
40 /**
41 * datepicker
42 */
43 const MONTH_NAMES = [
44 "January",
45 "February",
46 "March",
47 "April",
48 "May",
49 "June",
50 "July",
51 "August",
52 "September",
53 "October",
54 "November",
55 "December",
56 ];
57 const MONTH_SHORT_NAMES = [
58 "Jan",
59 "Feb",
60 "Mar",
61 "Apr",
62 "May",
63 "Jun",
64 "Jul",
65 "Aug",
66 "Sep",
67 "Oct",
68 "Nov",
69 "Dec",
70 ];
71 const DAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
72
73 function app() {
74 return {
75 showDatepicker: false,
76 datepickerValue: "",
77 selectedDate: calculateDatefromDays(),
78 dateFormat: "DD-MM-YYYY",
79 month: "",
80 year: "",
81 no_of_days: [],
82 blankdays: [],
83 initDate() {
84 let today;
85 if (this.selectedDate) {
86 today = new Date(Date.parse(this.selectedDate));
87 } else {
88 today = new Date();
89 }
90 this.month = today.getMonth();
91 this.year = today.getFullYear();
92 this.datepickerValue = this.formatDateForDisplay(
93 today
94 );
95 },
96 formatDateForDisplay(date) {
97 let formattedDay = DAYS[date.getDay()];
98 let formattedDate = ("0" + date.getDate()).slice(
99 -2
100 ); // appends 0 (zero) in single digit date
101 let formattedMonth = MONTH_NAMES[date.getMonth()];
102 let formattedMonthShortName =
103 MONTH_SHORT_NAMES[date.getMonth()];
104 let formattedMonthInNumber = (
105 "0" +
106 (parseInt(date.getMonth()) + 1)
107 ).slice(-2);
108 let formattedYear = date.getFullYear();
109 if (this.dateFormat === "DD-MM-YYYY") {
110 return `${formattedDate}-${formattedMonthInNumber}-${formattedYear}`; // 02-04-2021
111 }
112 if (this.dateFormat === "YYYY-MM-DD") {
113 return `${formattedYear}-${formattedMonthInNumber}-${formattedDate}`; // 2021-04-02
114 }
115 if (this.dateFormat === "D d M, Y") {
116 return `${formattedDay} ${formattedDate} ${formattedMonthShortName} ${formattedYear}`; // Tue 02 Mar 2021
117 }
118 return `${formattedDay} ${formattedDate} ${formattedMonth} ${formattedYear}`;
119 },
120 isSelectedDate(date) {
121 const d = new Date(this.year, this.month, date);
122 return this.datepickerValue ===
123 this.formatDateForDisplay(d) ?
124 true :
125 false;
126 },
127 isToday(date) {
128 const today = new Date();
129 const d = new Date(this.year, this.month, date);
130 return today.toDateString() === d.toDateString() ?
131 true :
132 false;
133 },
134 getDateValue(date) {
135 let selectedDate = new Date(
136 this.year,
137 this.month,
138 date
139 );
140 this.datepickerValue = this.formatDateForDisplay(
141 selectedDate
142 );
143 calculateDateinDays(selectedDate);
144 // this.$refs.date.value = selectedDate.getFullYear() + "-" + ('0' + formattedMonthInNumber).slice(-2) + "-" + ('0' + selectedDate.getDate()).slice(-2);
145 this.isSelectedDate(date);
146 this.showDatepicker = false;
147 },
148 getNoOfDays() {
149 let daysInMonth = new Date(
150 this.year,
151 this.month + 1,
152 0
153 ).getDate();
154 // find where to start calendar day of week
155 let dayOfWeek = new Date(
156 this.year,
157 this.month
158 ).getDay();
159 let blankdaysArray = [];
160 for (var i = 1; i <= dayOfWeek; i++) {
161 blankdaysArray.push(i);
162 }
163 let daysArray = [];
164 for (var i = 1; i <= daysInMonth; i++) {
165 daysArray.push(i);
166 }
167 this.blankdays = blankdaysArray;
168 this.no_of_days = daysArray;
169 }
170 };
171 }
172
173 function calculateDateinDays(selectedDate){
174 const today = new Date();
175 const diffTime = Math.abs(today - selectedDate);
176 const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24));
177 document.getElementById("deloldpDays").value = (diffDays - 1);
178 }
179
180 function calculateDatefromDays(){
181 selectedDays = document.getElementById("deloldpDays").value;
182 var d = new Date();
183 d.setDate(d.getDate() - selectedDays);
184 setDate = d.toISOString().slice(0, 10);
185 if(selectedDays != ''){
186 return setDate;
187 } else return "";
188 }