From 456a36e8295b1c21825a9ea23f804d6c32f564a6 Mon Sep 17 00:00:00 2001 From: Jared WIdeman Date: Wed, 10 Aug 2022 16:31:25 -0400 Subject: [PATCH] add yahoo import feature --- chrome/css/popup.css | 18 ++++++++++++++++++ chrome/index.html | 2 ++ chrome/manifest.json | 6 +++++- chrome/src/js/popup.js | 26 ++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 1 deletion(-) diff --git a/chrome/css/popup.css b/chrome/css/popup.css index 25fcfe5..55b73a6 100644 --- a/chrome/css/popup.css +++ b/chrome/css/popup.css @@ -87,6 +87,24 @@ img { font-weight: normal; } +#yahooInput { + padding: 4px; + padding-left: 6px; + width: 60%; + border: 1px solid lightgray; + border-radius: 2px; +} + +#yahooInput:focus { + outline: 0; +} + +#yahooInput::placeholder { + color: lightgray; + font-size: 14px; + font-weight: normal; +} + #addBtn { border: none; } diff --git a/chrome/index.html b/chrome/index.html index 5d62ce9..93b2afe 100755 --- a/chrome/index.html +++ b/chrome/index.html @@ -20,6 +20,8 @@ + +
diff --git a/chrome/manifest.json b/chrome/manifest.json index a7ed843..63c11e7 100755 --- a/chrome/manifest.json +++ b/chrome/manifest.json @@ -20,7 +20,11 @@ "permissions": [ "notifications", "storage", - "tabs" + "tabs", + "https://baseball.fantasysports.yahoo.com/*", + "http://baseball.fantasysports.yahoo.com/*", + "https://www.baseball.fantasysports.yahoo.com/*", + "http://www.baseball.fantasysports.yahoo.com/*" ], "content_security_policy": "script-src 'self' https://ssl.google-analytics.com; object-src 'self'" } diff --git a/chrome/src/js/popup.js b/chrome/src/js/popup.js index e27ce26..72d8b4c 100644 --- a/chrome/src/js/popup.js +++ b/chrome/src/js/popup.js @@ -14,8 +14,10 @@ _gaq.push(['_trackPageLoadTime']); document.addEventListener('DOMContentLoaded', function () { let link = document.getElementById('addBtn') + let yahooAdd = document.getElementById('importBtn') // onClick's logic below: link.addEventListener('click', handleIdInput) + yahooAdd.addEventListener('click', handleYahooImport) document.getElementById('notifBtn').addEventListener('click', handleNotifBtnClick) document.getElementById('muteBtn').addEventListener('click', handleMuteBtnClick) @@ -287,6 +289,30 @@ function handleIdInput () { } } +function normalizeName (name) { + return name.normalize("NFD").replace(/[\u0300-\u036f]/g, ""); +} + +function populate (html) { + let players = html.match(/(?<=[0-9]+".*_blank">).*(?=<\/a>)/gm); + players = players.map(player => normalizeName(player)); + players.forEach(player => { + sendMessageToBackGround('insert', findPlayerByName(player).id); + }); +} + +function handleYahooImport () { + let id = $('#yahooInput').val() + + $.ajax({ + url: `https://baseball.fantasysports.yahoo.com/b1/${id}`, + type: 'get', + dataType: 'html', + crossDomain: true, + success: populate + }) +} + function openTab(args) { let link = args.target.value chrome.tabs.create({url: link})