Skip to content

Instantly share code, notes, and snippets.

@pbojinov
Created October 14, 2019 18:56
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pbojinov/d572b5494a4f26390aeb5136d7097655 to your computer and use it in GitHub Desktop.
Save pbojinov/d572b5494a4f26390aeb5136d7097655 to your computer and use it in GitHub Desktop.
Safeway Just For You - Automatic Coupon Clipper
javascript:(function() {"use strict"; var coupons = angular.element("#lt-coupon-area").scope().sharedValues.unfilteredItems.slice(); coupons.filter(function(x){return x.clipStatus==="U";}).forEach(function(item){ var c1 = document.cookie.match(new RegExp('swyConsumerlbcookie=([^;]+)'))[1]; var c2 = document.cookie.match(new RegExp('swyConsumerDirectoryPro=([^;]+)'))[1]; var data = {"items":[]}; var clip = {}; clip.clipType="C";clip.itemId=item.offerId;clip.itemType=item.offerPgm;clip.vndrBannerCd=""; var list = {}; list.clipType="L";list.itemId=item.offerId;list.itemType=item.offerPgm; data.items.push(clip);data.items.push(list); var request = new Request('https://nimbus.safeway.com/Clipping1/services/clip/items', { method: 'POST', mode: 'cors', redirect: 'error', headers: new Headers({ 'Content-Type': 'application/json', 'X-SWY_VERSION': '1.0', 'X-SWY_API_KEY': 'emjou', 'X-SWY_BANNER': 'safeway', 'SWY_ISREMEMBERED': 'false', 'X-swyConsumerlbcookie': c1, 'X-swyConsumerDirectoryPro': c2 }), body: JSON.stringify(data) }); fetch(request).then(function(){ document.querySelector("#headerMyListCount").textContent = parseInt(document.querySelector("#headerMyListCount").textContent,10)+1; }); }); alert('clipping ' + coupons.filter(function(x){return x.clipStatus==="U"}).length + ' J4U coupons');}());
function() {
"use strict";
var coupons = angular.element("#lt-coupon-area").scope().sharedValues.unfilteredItems.slice();
coupons.filter(function(x) {
return x.clipStatus === "U";
}).forEach(function(item) {
var c1 = document.cookie.match(new RegExp('swyConsumerlbcookie=([^;]+)'))[1];
var c2 = document.cookie.match(new RegExp('swyConsumerDirectoryPro=([^;]+)'))[1];
var data = {
"items": []
};
var clip = {};
clip.clipType = "C";
clip.itemId = item.offerId;
clip.itemType = item.offerPgm;
clip.vndrBannerCd = "";
var list = {};
list.clipType = "L";
list.itemId = item.offerId;
list.itemType = item.offerPgm;
data.items.push(clip);
data.items.push(list);
var request = new Request('https://nimbus.safeway.com/Clipping1/services/clip/items', {
method: 'POST',
mode: 'cors',
redirect: 'error',
headers: new Headers({
'Content-Type': 'application/json',
'X-SWY_VERSION': '1.0',
'X-SWY_API_KEY': 'emjou',
'X-SWY_BANNER': 'safeway',
'SWY_ISREMEMBERED': 'false',
'X-swyConsumerlbcookie': c1,
'X-swyConsumerDirectoryPro': c2
}),
body: JSON.stringify(data)
});
fetch(request).then(function() {
document.querySelector("#headerMyListCount").textContent = parseInt(document.querySelector("#headerMyListCount").textContent, 10) + 1;
});
});
alert('clipping ' + coupons.filter(function(x) {
return x.clipStatus === "U"
}).length + ' J4U coupons');
}();
@sierralx
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment