diff --git a/package.json b/package.json index 125f805..f4c9e76 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "kleinanzeigen-magic", - "version": "0.7.0", + "version": "0.8.0", "description": "Speed up your Kleinanzeigen workflows!", "productName": "Kleinanzeigen Magic", "author": "Robert Honz ", diff --git a/src-electron/main-process/kleinanzeigen-workflow.js b/src-electron/main-process/kleinanzeigen-workflow.js index 4213b93..4146154 100644 --- a/src-electron/main-process/kleinanzeigen-workflow.js +++ b/src-electron/main-process/kleinanzeigen-workflow.js @@ -108,6 +108,8 @@ export const adTopUp = async (id, price, title) => { const regexContactName = /.*<\/ad:contact-name>/; const regexAttr = /.*<\/attr:attributes>/; const regexShipping = /.*<\/ns6:shipping-options>/; + const regexImprint = /.*<\/ad:imprint>/; + const regexPhone = /.*<\/ad:phone>/; let ad = null; let xmlPictures = ''; @@ -129,7 +131,7 @@ export const adTopUp = async (id, price, title) => { let adTitle = adXmlPrice.match(regexTitle); adXmlPost += adTitle; adXmlPost += adXmlPrice.match(regexTitle); - // Weird library behavior: Until proper decode you need to decode the string twice. + // Weird library behavior: To decode properly you need to decode the string twice. let adXmlDescTmp = adXmlPrice.match(regexDesc)[1]; let adXmlDescTmpDec = he.decode(adXmlDescTmp); let adXmlDescTmpDecDec = he.decode(adXmlDescTmpDec); @@ -142,6 +144,19 @@ export const adTopUp = async (id, price, title) => { adXmlPost += adXmlPrice.match(regexContactName); adXmlPost += adXmlPrice.match(regexShipping); adXmlPost += adXmlPrice.match(regexAttr); + + // Check if imprint stuff is available + const resImprint = adXmlPrice.match(regexImprint); + const resPhone = adXmlPrice.match(regexPhone); + + if (resImprint) { + adXmlPost += resImprint; + } + + if (resPhone) { + adXmlPost += resPhone; + } + adXmlPost += xmlPictures; adXmlPost += ''; diff --git a/src/pages/Overview.vue b/src/pages/Overview.vue index 768cd2f..9f50e07 100644 --- a/src/pages/Overview.vue +++ b/src/pages/Overview.vue @@ -5,6 +5,21 @@ q-btn-group(spread) q-btn(@click="openExternal('https://www.ebay-kleinanzeigen.de/')", icon="language", label="Kleinanzeigen Portal") q-btn(@click="getAds()", icon="refresh", label="Anzeigen") + .row.q-gutter-y-sm + .col + q-banner.bg-red.text-black + template(v-slot:avatar) + q-icon(name="announcement") + | This app is still a BETA. Please note that bugs may occur which may result in unrecoverable or incorrect displayed ads. + | Use it at your own risk! + .row.q-gutter-y-sm(v-if="!allowTopUp") + .col + q-banner.bg-orange.text-black + template(v-slot:avatar) + q-icon(name="warning") + | You have created / topped-up more then {{ checkAllowTopUpMaxAds }} ads in the past {{ checkAllowTopUpDays }} days. + | According to Kleinanzeigen you are not allowed to create more than {{ checkAllowTopUpMaxAds + 1 }} ads in this time period. + | The top-up function is therefore suspended until you fall below the limit value again. .row.q-pa-md.q-gutter-y-sm(v-if="!adsLoading", v-for="ad in ads", :key="ad.id") .col-12 q-card @@ -39,7 +54,7 @@ q-btn-group(outline) q-btn(flat, :icon="ad['ad-status'].value == 'ACTIVE' ? 'public_off' : 'public'", @click="adPauseResume(ad['ad-status'].value == 'ACTIVE' ? 'pause' : 'resume', ad.id)") q-tooltip Anzeige deaktivieren. - q-btn(outline, color="green", @click="dialogTopUpShow(ad)") + q-btn(outline, color="green", @click="dialogTopUpShow(ad)", :disable="!allowTopUp") q-icon.rotate-270(name="double_arrow") q-tooltip Anzeige gratis nach oben schieben. q-btn(flat, color="red", icon="delete_forever", @click="dialogDeleteShow(ad)") @@ -106,13 +121,20 @@ export default { title: null, editable: true }, - adsLoading: false + adsLoading: false, + allowTopUp: true, + checkAllowTopUpDays: 30, + checkAllowTopUpMaxAds: 49, + dayInMs: 86400000 }; }, mounted: function () { this.$q.electron.ipcRenderer.on('m-get-ads', (event, arg) => { this.ads = arg; + + this.checkAllowTopUp(); + this.adsLoading = false; }); @@ -254,6 +276,31 @@ export default { this.$q.loading.show({ message: 'Ich tue mein Bestes! Bitte warten...' }); + }, + checkAllowTopUp: function () { + const adsInTimeScope = this.countNewAdsInPastDays(this.ads, this.checkAllowTopUpDays); + + if (adsInTimeScope > this.checkAllowTopUpMaxAds) { + this.allowTopUp = false; + } else { + this.allowTopUp = true + } + }, + countNewAdsInPastDays: function (ads, daysMax) { + const now = new Date(); + let adsInTimeScope = 0; + + for (let adItem of ads) { + const then = new Date(adItem['start-date-time']['value']); + const msBetweenDates = Math.abs(then.getTime() - now.getTime()); + const daysBetweenDates = msBetweenDates / this.dayInMs; + + if (daysBetweenDates < 30) { + adsInTimeScope++; + } + } + + return adsInTimeScope; } } };