Skip to content

Commit

Permalink
fix mini-toastr blocking content
Browse files Browse the repository at this point in the history
  • Loading branch information
miniers committed Aug 1, 2017
1 parent 79fe6f3 commit 76b358a
Show file tree
Hide file tree
Showing 11 changed files with 237 additions and 12 deletions.
8 changes: 4 additions & 4 deletions safari2aria.safariextension/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@
<key>Author</key>
<string>Miniers</string>
<key>Builder Version</key>
<string>12603.2.4</string>
<string>12603.3.8</string>
<key>CFBundleDisplayName</key>
<string>safari2aria</string>
<key>CFBundleIdentifier</key>
<string>miniers.safari2aria</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>1.0</string>
<key>CFBundleShortVersionString</key>
<string>2.9</string>
<string>2.9.1</string>
<key>CFBundleVersion</key>
<string>2.9</string>
<string>2.9.1</string>
<key>Chrome</key>
<dict>
<key>Database Quota</key>
Expand Down Expand Up @@ -87,7 +87,7 @@
<key>Update From Gallery</key>
<true/>
<key>Update Manifest URL</key>
<string>https://miniers.github.io/safari2aria/update.plist?t=2.8.3</string>
<string>https://miniers.github.io/safari2aria/update.plist?t=2.9.1</string>
<key>Website</key>
<string>https://github.com/miniers/safari2aria</string>
</dict>
Expand Down
2 changes: 1 addition & 1 deletion safari2aria.safariextension/global.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<body>
<div id="app-box"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.c1acd049edbf1f576628.js"></script><script type="text/javascript" src="static/js/global.9b88090145ceb8e14093.js"></script></body>
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.b06a56798f24a0ca629d.js"></script><script type="text/javascript" src="static/js/global.9b88090145ceb8e14093.js"></script></body>
</html>
2 changes: 1 addition & 1 deletion safari2aria.safariextension/options.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<body>
<div id="app-box"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.c1acd049edbf1f576628.js"></script><script type="text/javascript" src="static/js/options.655cdd63c4197e7f9d17.js"></script></body>
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.b06a56798f24a0ca629d.js"></script><script type="text/javascript" src="static/js/options.655cdd63c4197e7f9d17.js"></script></body>
</html>
2 changes: 1 addition & 1 deletion safari2aria.safariextension/popover.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
<body>
<div id="app-box"></div>
<!-- built files will be auto injected -->
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.c1acd049edbf1f576628.js"></script><script type="text/javascript" src="static/js/popover.7d97ede0d15e59a0a5db.js"></script></body>
<script type="text/javascript" src="static/js/manifest.js"></script><script type="text/javascript" src="static/js/vendor.b06a56798f24a0ca629d.js"></script><script type="text/javascript" src="static/js/popover.f22dd649b44e14ff4c32.js"></script></body>
</html>
2 changes: 1 addition & 1 deletion safari2aria.safariextension/static/js/endscript.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion safari2aria.safariextension/static/js/manifest.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Binary file modified safari2aria.safariextz
Binary file not shown.
2 changes: 1 addition & 1 deletion src/js/endscript/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import toastr from 'mini-toastr'
import toastr from '@/public/mini-toastr'
import bdlx from './baiduLixian'
import downloadAble from '@/public/downloadAble'
import messageListener from '@/public/pageScriptMessage'
Expand Down
225 changes: 225 additions & 0 deletions src/public/mini-toastr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,225 @@
function fadeOut (element, cb) {
if (element.style.opacity && element.style.opacity > 0.05) {
element.style.opacity = element.style.opacity - 0.05
} else if (element.style.opacity && element.style.opacity <= 0.1) {
if (element.parentNode) {
if(element.parentNode.children.length<=1){
element.parentNode.style.display='none'
}
element.parentNode.removeChild(element)
if (cb) cb()
}else{
return false;
}
} else {
element.style.opacity = 0.9
}
setTimeout(() => fadeOut.apply(this, [element, cb]), 1000 / 30)
}

const TYPES = {
error: 'error',
warn: 'warn',
success: 'success',
info: 'info'
}

const CLASSES = {
container: 'mini-toastr-s2a',
notification: 'mini-toastr__notification',
title: 'mini-toastr-notification__title',
icon: 'mini-toastr-notification__icon',
message: 'mini-toastr-notification__message',
error: `-${TYPES.error}`,
warn: `-${TYPES.warn}`,
success: `-${TYPES.success}`,
info: `-${TYPES.info}`
}

function flatten (obj, into, prefix) {
into = into || {}
prefix = prefix || ''

for (let k in obj) {
if (obj.hasOwnProperty(k)) {
const prop = obj[k]
if (prop && typeof prop === 'object' && !(prop instanceof Date || prop instanceof RegExp)) {
flatten(prop, into, prefix + k + ' ')
} else {
if (into[prefix] && typeof into[prefix] === 'object') {
into[prefix][k] = prop
} else {
into[prefix] = {}
into[prefix][k] = prop
}
}
}
}

return into
}

function makeCss (obj) {
const flat = flatten(obj)
let str = JSON.stringify(flat, null, 2)
str = str.replace(/"([^"]*)": \{/g, '$1 {')
.replace(/"([^"]*)"/g, '$1')
.replace(/(\w*-?\w*): ([\w\d .#]*),?/g, '$1: $2;')
.replace(/},/g, '}\n')
.replace(/ &([.:])/g, '$1')

str = str.substr(1, str.lastIndexOf('}') - 1)

return str
}

function appendStyles (css) {
let head = document.head || document.getElementsByTagName('head')[0]
let styleElem = makeNode('style')
styleElem.id = 'mini-toastr-styles'
styleElem.type = 'text/css'

if (styleElem.styleSheet) {
styleElem.styleSheet.cssText = css
} else {
styleElem.appendChild(document.createTextNode(css))
}

head.appendChild(styleElem)
}

const config = {
types: TYPES,
animation: fadeOut,
timeout: 3000,
icons: {},
appendTarget: document.body,
node: makeNode(),
style: {
[`.${CLASSES.container}`]: {
position: 'fixed',
'z-index': 99999,
right: '12px',
top: '12px',
display:'none'
},
[`.${CLASSES.notification}`]: {
cursor: 'pointer',
padding: '12px 18px',
margin: '0 0 6px 0',
'background-color': '#000',
opacity: 0.8,
color: '#fff',
'border-radius': '3px',
'box-shadow': '#3c3b3b 0 0 12px',
width: '300px',
[`&.${CLASSES.error}`]: {
'background-color': '#D5122B'
},
[`&.${CLASSES.warn}`]: {
'background-color': '#F5AA1E'
},
[`&.${CLASSES.success}`]: {
'background-color': '#7AC13E'
},
[`&.${CLASSES.info}`]: {
'background-color': '#4196E1'
},
'&:hover': {
opacity: 1,
'box-shadow': '#000 0 0 12px'
}
},
[`.${CLASSES.title}`]: {
'font-weight': '500'
},
[`.${CLASSES.message}`]: {
display: 'inline-block',
'vertical-align': 'middle',
width: '240px',
padding: '0 12px'
}
}
}

function makeNode (type = 'div') {
return document.createElement(type)
}

function createIcon (node, type, config) {
const iconNode = makeNode(config.icons[type].nodeType)
const attrs = config.icons[type].attrs

for (const k in attrs) {
if (attrs.hasOwnProperty(k)) {
iconNode.setAttribute(k, attrs[k])
}
}

node.appendChild(iconNode)
}

function addElem (node, text, className) {
const elem = makeNode()
elem.className = className
elem.appendChild(document.createTextNode(text))
node.appendChild(elem)
}

const exports = {
config,
showMessage (message, title, type, timeout, cb, overrideConf) {
const config = {}
Object.assign(config, this.config)
Object.assign(config, overrideConf)

const notificationElem = makeNode()
notificationElem.className = `${CLASSES.notification} ${CLASSES[type]}`

notificationElem.onclick = function () {
config.animation(notificationElem, null)
}

if (title) addElem(notificationElem, title, CLASSES.title)
if (config.icons[type]) createIcon(notificationElem, type, config)
if (message) addElem(notificationElem, message, CLASSES.message)
config.node.style.display='block';
config.node.insertBefore(notificationElem, config.node.firstChild)
setTimeout(() => config.animation(notificationElem, cb), timeout || config.timeout)

if (cb) cb()
return this
},
init (aConfig) {
const newConfig = {}
Object.assign(newConfig, config)
Object.assign(newConfig, aConfig)
this.config = newConfig

const cssStr = makeCss(newConfig.style)
appendStyles(cssStr)

newConfig.node.id = `${CLASSES.container}`
newConfig.node.className = `${CLASSES.container}`
newConfig.appendTarget.appendChild(newConfig.node)

Object.keys(newConfig.types).forEach(v => {
exports[newConfig.types[v]] = function (message, title, timeout, cb, config) {
this.showMessage(message, title, newConfig.types[v], timeout, cb, config)
return this
}.bind(this)
})

return this
},
setIcon (type, nodeType = 'i', attrs = []) {
attrs.class = attrs.class ? attrs.class + ' ' + CLASSES.icon : CLASSES.icon

this.config.icons[type] = {
nodeType,
attrs
}
}
};

export default exports

0 comments on commit 76b358a

Please sign in to comment.