Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions chrome/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 2 additions & 0 deletions chrome/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
<input type='text' id='nameInput' placeholder="Search and Add a Player" />
<input type="hidden" id="playerId"/>
<button id='addBtn' class='btn btn-primary'>Add</button>
<input type='text' id='yahooInput' placeholder="Import Yahoo Lineup (example: 24181/2)" />
<button id='importBtn' class='btn btn-primary'>Import</button>
</div>
</center>
<div class = 'table-div'>
Expand Down
6 changes: 5 additions & 1 deletion chrome/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
}
26 changes: 26 additions & 0 deletions chrome/src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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})
Expand Down