This repository has been archived by the owner on Nov 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 183
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Format javascript according to StandardJS spec."
This reverts commit f66ec2d. This broke some JS functionality, so reverting for now and will revisit down the road.
- Loading branch information
1 parent
dc41fa8
commit 2fcf7b2
Showing
7 changed files
with
158 additions
and
160 deletions.
There are no files selected for viewing
6 changes: 3 additions & 3 deletions
6
Application/LinkBubble/src/main/assets/pagescripts/FetchContent.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
;(function () { | ||
window.LinkBubble.fetchHtml(document.documentElement.outerHTML, String(window.location)) | ||
})() | ||
(function() { | ||
window.LinkBubble.fetchHtml(document.documentElement.outerHTML, String(window.location)); | ||
})(); |
130 changes: 65 additions & 65 deletions
130
Application/LinkBubble/src/main/assets/pagescripts/SelectElements.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,68 @@ | ||
;(function () { | ||
if (window.LinkBubble.selectOption) { return } | ||
window.LinkBubble.lastSelectFocused = null | ||
window.LinkBubble.selectOption = function (index) { | ||
var select = window.LinkBubble.lastSelectFocused | ||
select.selectedIndex = index | ||
select.previousElementSibling.textContent = select[index].text | ||
} | ||
var positioningProps = ['float', 'position', 'width', 'height', 'left', 'top', 'margin-left', 'margin-top', 'padding-left', 'padding-top', 'border', 'background'] | ||
var els = document.getElementsByTagName('select') | ||
function maskSelects () { | ||
/* Remove all previous select masks if the next element is not a select any longer. */ | ||
Array.prototype.forEach.call(document.querySelectorAll('.__link_bubble__select_mask__'), function (mask) { | ||
if (mask.nextElementSibling && mask.nextElementSibling.nodeName.toLowerCase() === 'select') { return } | ||
mask.parentNode.removeChild(mask) | ||
}) | ||
(function() { | ||
if (window.LinkBubble.selectOption) { return; } | ||
LinkBubble.lastSelectFocused = null; | ||
LinkBubble.selectOption = function(index) { | ||
var select = LinkBubble.lastSelectFocused; | ||
select.selectedIndex = index; | ||
select.previousElementSibling.textContent = select[index].text; | ||
}; | ||
var positioningProps = ['float','position','width','height','left','top','margin-left','margin-top','padding-left','padding-top', 'border', 'background']; | ||
var els = document.getElementsByTagName('select'); | ||
function maskSelects() { | ||
/* Remove all previous select masks if the next element is not a select any longer. */ | ||
Array.prototype.forEach.call(document.querySelectorAll('.__link_bubble__select_mask__'), function(mask) { | ||
if (mask.nextElementSibling && mask.nextElementSibling.nodeName.toLowerCase() === 'select') { return; }; | ||
mask.parentNode.removeChild(mask); | ||
}); | ||
|
||
Array.prototype.forEach.call(els, function (select) { | ||
var mask = select.previousElementSibling | ||
/* Insert and style for new selects */ | ||
if (!mask || mask.className !== '__link_bubble__select_mask__') { | ||
mask = document.createElement('div') | ||
mask.className = '__link_bubble__select_mask__' | ||
mask.style.webkitAppearance = 'menulist' | ||
var computedStyle = window.getComputedStyle(select) | ||
Array.prototype.forEach.call(els, function(select) { | ||
var mask = select.previousElementSibling; | ||
/* Insert and style for new selects */ | ||
if (!mask || mask.className !== '__link_bubble__select_mask__') { | ||
mask = document.createElement('div'); | ||
mask.className = '__link_bubble__select_mask__'; | ||
mask.style.webkitAppearance = 'menulist'; | ||
var computedStyle = getComputedStyle(select); | ||
|
||
for (var i in positioningProps) { | ||
var prop = positioningProps[i] | ||
mask.style[prop] = computedStyle.getPropertyValue(prop) | ||
} | ||
select.parentNode.insertBefore(mask, select) | ||
select.style.display = 'none' | ||
for(var i in positioningProps){ | ||
var prop = positioningProps[i]; | ||
mask.style[prop] = computedStyle.getPropertyValue(prop); | ||
} | ||
select.parentNode.insertBefore(mask, select); | ||
select.style.display = 'none'; | ||
|
||
mask.addEventListener('click', function (e) { | ||
e.preventDefault() | ||
window.LinkBubble.lastSelectFocused = select | ||
var keyAndValues = [select.selectedIndex] | ||
for (var i = 0; i < select.length; i++) { | ||
keyAndValues.push(select[i].text) | ||
keyAndValues.push(select[i].value) | ||
} | ||
window.LinkBubble.onSelectElementInteract(JSON.stringify(keyAndValues)) | ||
}) | ||
} | ||
mask.textContent = select[select.selectedIndex].text | ||
}) | ||
} | ||
/* Mask all selects when the script is injected. */ | ||
maskSelects() | ||
/* Use a mutation observer for dynamic selects added after page load. */ | ||
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver | ||
var observer = new MutationObserver(function (mutations) { | ||
mutations.forEach(function (mutation) { | ||
var changed = false | ||
var allChangedNodes = [].slice.call(mutation.addedNodes).concat([].slice.call(mutation.removedNodes)) | ||
allChangedNodes.forEach(function (changedNode) { | ||
if ((changedNode.querySelector && changedNode.querySelector('select')) || changedNode.nodeName.toLowerCase() === 'select') { | ||
changed = true | ||
} | ||
}) | ||
if (changed) { | ||
maskSelects() | ||
} | ||
}) | ||
}) | ||
var config = {attributes: false, childList: true, characterData: false, subtree: true} | ||
observer.observe(document, config) | ||
})() | ||
mask.addEventListener('click', function(e) { | ||
e.preventDefault(); | ||
LinkBubble.lastSelectFocused = select; | ||
var keyAndValues = [select.selectedIndex]; | ||
for (var i = 0; i < select.length; i++) { | ||
keyAndValues.push(select[i].text); | ||
keyAndValues.push(select[i].value); | ||
} | ||
LinkBubble.onSelectElementInteract(JSON.stringify(keyAndValues)); | ||
}); | ||
} | ||
mask.textContent = select[select.selectedIndex].text; | ||
}); | ||
} | ||
/* Mask all selects when the script is injected. */ | ||
maskSelects(); | ||
/* Use a mutation observer for dynamic selects added after page load. */ | ||
MutationObserver = window.MutationObserver || window.WebKitMutationObserver; | ||
var observer = new MutationObserver(function(mutations) { | ||
mutations.forEach(function(mutation) { | ||
var changed = false; | ||
var allChangedNodes = [].slice.call(mutation.addedNodes).concat([].slice.call(mutation.removedNodes)); | ||
allChangedNodes.forEach(function(changedNode) { | ||
if ((changedNode.querySelector && changedNode.querySelector('select')) || changedNode.nodeName.toLowerCase() === 'select') { | ||
changed = true; | ||
} | ||
}); | ||
if (changed) { | ||
maskSelects(); | ||
} | ||
}); | ||
}); | ||
var config = {attributes: false, childList: true, characterData: false, subtree: true}; | ||
observer.observe(document, config); | ||
})(); |
12 changes: 6 additions & 6 deletions
12
Application/LinkBubble/src/main/assets/pagescripts/ThemeColor.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
;(function () { | ||
var themeColorTag = document.getElementsByTagName('meta')['theme-color'] | ||
if (themeColorTag) { | ||
window.LinkBubble.onThemeColor(themeColorTag.getAttribute('content')) | ||
} | ||
})() | ||
(function() { | ||
var themeColorTag = document.getElementsByTagName('meta')['theme-color']; | ||
if (themeColorTag) { | ||
LinkBubble.onThemeColor(themeColorTag.getAttribute('content')); | ||
} | ||
})(); |
40 changes: 20 additions & 20 deletions
40
Application/LinkBubble/src/main/assets/pagescripts/TouchIcon.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,21 @@ | ||
;(function () { | ||
var links = document.head.getElementsByTagName('link') | ||
var linksArray = null | ||
var linksCount = 0 | ||
for (var link in links) { | ||
if (links.hasOwnProperty(link)) { | ||
var l = links[link] | ||
if (l.rel != null && l.rel.indexOf('apple-touch-icon') !== -1) { | ||
if (linksArray == null) { | ||
linksArray = [ ] | ||
(function() { | ||
var links = document.head.getElementsByTagName('link'); | ||
var linksArray = null; | ||
var linksCount = 0; | ||
for(var link in links){ | ||
if(links.hasOwnProperty(link)){ | ||
var l = links[link]; | ||
if (l.rel != null && l.rel.indexOf('apple-touch-icon') != -1) { | ||
if (linksArray == null) { | ||
linksArray = new Array(); | ||
} | ||
var s = "@@@" + l.rel + "," + l.href + "," + l.sizes + "###"; | ||
linksArray[linksCount] = s; | ||
linksCount++; | ||
} | ||
} | ||
var s = '@@@' + l.rel + ',' + l.href + ',' + l.sizes + '###' | ||
linksArray[linksCount] = s | ||
linksCount++ | ||
} | ||
} | ||
} | ||
if (linksCount > 0) { | ||
window.LinkBubble.onTouchIconLinks(linksArray.toString()) | ||
} | ||
})() | ||
} | ||
if (linksCount > 0) { | ||
LinkBubble.onTouchIconLinks(linksArray.toString()); | ||
} | ||
})(); |
41 changes: 20 additions & 21 deletions
41
Application/LinkBubble/src/main/assets/pagescripts/YouTube.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,23 @@ | ||
;(function () { | ||
function detectYoutubeEmbeds () { | ||
var elems = document.getElementsByTagName('*') | ||
var i | ||
var YOUTUBE_EMBED_PREFIX = '//www.youtube.com/embed/' | ||
var resultArray = null | ||
var resultCount = 0 | ||
for (i in elems) { | ||
var elem = elems[i] | ||
if (elem.src != null && elem.src.indexOf(YOUTUBE_EMBED_PREFIX) !== -1) { | ||
if (resultArray == null) { | ||
resultArray = [ ] | ||
(function() { | ||
function detectYoutubeEmbeds() { | ||
var elems = document.getElementsByTagName('*'), i; | ||
var YOUTUBE_EMBED_PREFIX = "//www.youtube.com/embed/"; | ||
var resultArray = null; | ||
var resultCount = 0; | ||
for (i in elems) { | ||
var elem = elems[i]; | ||
if (elem.src != null && elem.src.indexOf(YOUTUBE_EMBED_PREFIX) != -1) { | ||
if (resultArray == null) { | ||
resultArray = new Array(); | ||
} | ||
resultArray[resultCount] = elem.src; | ||
resultCount++; | ||
} | ||
} | ||
if (resultCount > 0) { | ||
LinkBubble.onYouTubeEmbeds(resultArray.toString()); | ||
} | ||
resultArray[resultCount] = elem.src | ||
resultCount++ | ||
} | ||
} | ||
if (resultCount > 0) { | ||
window.LinkBubble.onYouTubeEmbeds(resultArray.toString()) | ||
} | ||
} | ||
|
||
detectYoutubeEmbeds() | ||
})() | ||
detectYoutubeEmbeds(); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,74 +1,75 @@ | ||
let fs = require('fs') | ||
let path = require('path') | ||
var https = require('https') | ||
let fs = require('fs'); | ||
let path = require('path'); | ||
let child_process = require('child_process'); | ||
var https = require('https'); | ||
|
||
if (process.argv.length !== 4) { | ||
console.error('usage: babel-node udpateTranslations.js <username> <password>') | ||
process.exit(0) | ||
if (process.argv.length != 4) { | ||
console.error('usage: babel-node udpateTranslations.js <username> <password>'); | ||
process.exit(0); | ||
} | ||
|
||
const username = process.argv[2] | ||
const password = process.argv[3] | ||
const username = process.argv[2]; | ||
const password = process.argv[3]; | ||
|
||
const request = (path) => { | ||
return new Promise((resolve, reject) => { | ||
return https.get({ | ||
host: 'api.getlocalization.com', | ||
path, | ||
method: 'GET', | ||
auth: `${username}:${password}` | ||
auth: `${username}:${password}`, | ||
}, function (res) { | ||
res.setEncoding('utf8') | ||
let body = '' | ||
res.setEncoding('utf8'); | ||
let body = ''; | ||
res.on('data', function (chunk) { | ||
body += chunk | ||
}) | ||
body += chunk; | ||
}); | ||
res.on('end', function () { | ||
if (res.statusCode !== 200) { | ||
reject(res.statusCode) | ||
reject(res.statusCode); | ||
} else { | ||
resolve(body) | ||
resolve(body); | ||
} | ||
}) | ||
}) | ||
}) | ||
} | ||
const requestTranslations = request.bind(null, '/LinkBubble/api/translations/list/json/') | ||
const requestTranslationFile = (masterFile, languageTag) => request(`/LinkBubble/api/translations/file/${masterFile}/${languageTag}/`) | ||
}); | ||
}); | ||
}); | ||
}; | ||
const requestTranslations = request.bind(null, '/LinkBubble/api/translations/list/json/'); | ||
const requestTranslationFile = (masterFile, languageTag) => request(`/LinkBubble/api/translations/file/${masterFile}/${languageTag}/`); | ||
|
||
// List of locales that are downloaded that we don't want | ||
const ignoreList = ['es-419', 'grk'] | ||
const ignoreList = ['es-419', 'grk']; | ||
|
||
requestTranslations().then(translations => { | ||
translations = JSON.parse(translations).filter(translation => !ignoreList.includes(translation.iana_code)) | ||
translations = JSON.parse(translations).filter(translation => !ignoreList.includes(translation.iana_code)); | ||
Promise.all(translations.reduce((allPromises, translation) => { | ||
allPromises.push(requestTranslationFile(translation.master_file, translation.iana_code)) | ||
return allPromises | ||
allPromises.push(requestTranslationFile(translation.master_file, translation.iana_code)); | ||
return allPromises; | ||
}, [translations])).then(values => { | ||
values = values.slice(1) | ||
values = values.slice(1); | ||
if (translations.length !== values.length) { | ||
console.error('Not all translations could be downloaded, aborting') | ||
process.exit(1) | ||
console.error('Not all translations could be downloaded, aborting'); | ||
process.exit(1); | ||
} | ||
|
||
for (let i = 0; i < translations.length; i++) { | ||
let translation = translations[i] | ||
let fileData = values[i] | ||
let translation = translations[i]; | ||
let fileData = values[i]; | ||
|
||
// Android calls: en-US -> en-rUS | ||
let filename = translation.iana_code.split('-').join('-r') | ||
let toPath = `./Application/LinkBubble/src/main/res/values-${filename}` | ||
if (!fs.existsSync(toPath)) { | ||
fs.mkdirSync(toPath) | ||
let filename = translation.iana_code.split('-').join('-r'); | ||
let toPath = `./Application/LinkBubble/src/main/res/values-${filename}`; | ||
if (!fs.existsSync(toPath)) { | ||
fs.mkdirSync(toPath); | ||
} | ||
|
||
toPath = path.join(toPath, translation.master_file) | ||
fs.writeFileSync(toPath, fileData) | ||
toPath = path.join(toPath, translation.master_file); | ||
fs.writeFileSync(toPath, fileData); | ||
} | ||
console.log('Success!') | ||
}) | ||
}) | ||
console.log('Success!'); | ||
}); | ||
}); | ||
|
||
process.on('uncaughtException', function (err) { | ||
console.log('Caught exception: ' + err) | ||
}) | ||
console.log('Caught exception: ' + err); | ||
}); |