Skip to content

Commit

Permalink
github所有页面都加入了trending
Browse files Browse the repository at this point in the history
把所有的样式都用id做的,然后去掉了class,和不必要的class
  • Loading branch information
maicss committed Aug 25, 2017
1 parent 06f54b3 commit 550bd5c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 45 deletions.
57 changes: 28 additions & 29 deletions css/popup.css → css/popover.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
min-height: unset;
}

#shanbay-popover .btn {
#shanbay-popover .shanbay-btn {
display: inline-block;
padding: 4px 12px;
margin-bottom: 0;
Expand All @@ -59,15 +59,15 @@
border-radius: 2px;
}

#shanbay-popover .btn-success:hover,
#shanbay-popover .btn-success:focus,
#shanbay-popover .btn-success:active,
#shanbay-popover .btn-success.active {
#shanbay-popover .shanbay-btn:hover,
#shanbay-popover .shanbay-btn:focus,
#shanbay-popover .shanbay-btn:active,
#shanbay-popover .shanbay-btn.active {
color: #fff;
background-color: #38c2a8;
}

#shanbay-popover.popover {
#shanbay-popover {
position: absolute;
box-sizing: border-box;
top: 0;
Expand All @@ -85,14 +85,14 @@
white-space: normal;
visibility: visible;
overflow: visible;
}

#shanbay-popover.popover.bottom {
margin-top: 10px;
bottom: unset;
opacity: 1;
height: initial;
transition: opacity 0.15s linear;
}

#shanbay-popover .popover-title {
#shanbay-popover #shanbay-title {
background-color: white;
margin: 0;
padding: 8px 14px;
Expand All @@ -102,12 +102,21 @@
border-bottom: 1px solid #ebebeb;
}

#shanbay-popover .popover-content {
#shanbay-popover #shanbay-content {
padding: 9px 14px;
}

#shanbay-popover.popover .arrow,
#shanbay-popover.popover .arrow:after {
#shanbay-popover #shanbay-content .simple-definition {
margin-bottom: 20px;
font-size: 16px;
}

#shanbay-popover #shanbay-content .add {
text-align: right;
}

#shanbay-popover #shanbay-arrow,
#shanbay-popover #shanbay-arrow:after {
content: "";
position: absolute;
display: block;
Expand All @@ -116,31 +125,31 @@
border: 10px transparent solid;
}

#shanbay-popover.popover .arrow {
#shanbay-popover #shanbay-arrow {
border-width: 11px;
}

#shanbay-popover .popover-content p {
#shanbay-popover #shanbay-content p {
margin: 0;
padding: 0;
}

#shanbay-popover.popover.bottom .arrow {
#shanbay-popover #shanbay-arrow {
left: 50%;
margin-left: -11px;
border-top-width: 0;
border-bottom-color: rgba(0, 0, 0, 0.25);
top: -11px;
}

#shanbay-popover.popover.bottom .arrow:after {
#shanbay-popover #shanbay-arrow:after {
top: 1px;
margin-left: -10px;
border-top-width: 0;
border-bottom-color: #fff;
}

#shanbay-popover .popover-inner {
#shanbay-popover #shanbay-inner {
padding: 0;
width: 276px;
overflow: hidden;
Expand All @@ -149,18 +158,8 @@
box-shadow: none;
}

#shanbay-popover .popover-title .word {
#shanbay-popover #shanbay-title .word {
font-size: 25px;
font-weight: normal;
font-family: Lucida Sans Unicode, Lucida Grande, sans-serif;
}

#shanbay-popover.fade {
opacity: 0;
transition: opacity 0.15s linear;
}

#shanbay-popover.fade.in {
opacity: 1;
height: initial;
}
5 changes: 3 additions & 2 deletions js/github-avatar.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const actionArr = ['starred', 'created', 'forked', 'watched', 'follow']

const addTends = () => {
// const tendUrl = 'https://github.com/trending'
document.querySelector('header.Header ul[role=navigation]').insertAdjacentHTML('beforeEnd', '<li><a class="js-selected-navigation-item HeaderNavlink px-2" href="/trending">trending</a></li>')
const ul = document.querySelector('header.Header ul[role=navigation]')
if (ul) ul.insertAdjacentHTML('beforeEnd', '<li><a class="js-selected-navigation-item HeaderNavlink px-2" href="/trending">trending</a></li>')
}
/**
* GitHub 动态首页添加头像
Expand Down Expand Up @@ -46,7 +47,7 @@ chrome.storage.sync.get('chromeShanbaySettings', (settings) => {
addTends()
}

if (storage.avatar) {
if (storage.avatar && (location.href === 'https://github.com' || location.href === 'https://github.com/')) {
addAvatar()

const observer = new MutationObserver(function (mutations) {
Expand Down
24 changes: 12 additions & 12 deletions js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ const popover = (res) => {
}

/** 先根据选区确定弹出框的位置,生成弹出框,然后根据参数和设置,往里面插入内容*/
let html = `<div id="shanbay-popover" style="top: ${offset.top}px; left: ${offset.left}px; display: block" class="fade bottom in popover"><div class="arrow" style= ${offset.distance ? 'left:' + offset.distance + 'px' : ''}></div><div class="popover-inner"><div class="popover-title" style="border: none;"></div></div></div>`
let html = `<div id="shanbay-popover" style="top: ${offset.top}px; left: ${offset.left}px; display: block"><div id="shanbay-arrow" style= ${offset.distance ? 'left:' + offset.distance + 'px' : ''}></div><div id="shanbay-inner"><div id="shanbay-title" style="border: none;"></div></div></div>`

/** 这里是为了防止多次调用popover产生多个弹出框的。因为一次查询最起码会调用两次popover*/
if (!document.querySelector('#shanbay-popover')) {
Expand All @@ -91,12 +91,12 @@ const popover = (res) => {

if (res.loading) {
/** 查询之前和未登录的提示信息*/
document.querySelector('#shanbay-popover .popover-title').innerHTML = res.msg
document.querySelector('#shanbay-popover #shanbay-title').innerHTML = res.msg
} else if (res.status_code === 0) {
/** 查询单词或者单词其他操作成功*/
let data = res.data
let contentHtml = `
<div class="popover-title">
<div id="shanbay-title">
<span class="word">${data.content}</span>
<a href="https://www.shanbay.com/bdc/vocabulary/${data.id}" style="float: right;" target="_blank"> 详细</a>
<div>
Expand All @@ -109,20 +109,20 @@ const popover = (res) => {
</div>
</div>
<div class="popover-content">
<div class="simple-definition" style="margin-bottom: 20px; font-size: 16px;">
<div id="shanbay-content">
<div class="simple-definition">
${storage.paraphrase !== 'English' ? (data.cn_definition.pos ? `<div><strong>${data.cn_definition.pos} </strong><span>${data.cn_definition.defn}</span></div>` : data.cn_definition.defn ? data.cn_definition.defn.split('\n').join('<br>') : '' ) : ''}
${ storage.paraphrase !== 'Chinese' ? Object.keys(data.en_definitions).map(pos => `<div><span>${pos}. </span><span>${data.en_definitions[pos].join(';')}</span></div>`).join('') : ''}
</div>
<div class="add" style="text-align: right;">
${data.learning_id ? `<p id="shanbay-forget-word"><button class="forget pull-right btn btn-success">我忘了</button></p>` : `<p><button id="shanbay-add-word" class="btn btn-success">添加</button></p>`}
<p class="hide" id="shanbay-under-adding" style="text-align: right;"><span class="loading">正在添加</span></p>
<div class="add">
${data.learning_id ? `<p id="shanbay-forget-word"><button class="forget shanbay-btn">我忘了</button></p>` : `<p><button id="shanbay-add-word" class="shanbay-btn">添加</button></p>`}
<p class="hide" id="shanbay-under-adding"><span class="loading">正在添加</span></p>
</div>
<div id="shanbay-add-result" class="hide"></div>
</div>
`

document.querySelector('#shanbay-popover .popover-inner').innerHTML = contentHtml;
document.querySelector('#shanbay-popover #shanbay-inner').innerHTML = contentHtml;

/** 各种事件的处理*/
/** 发音事件的处理 */
Expand Down Expand Up @@ -154,11 +154,11 @@ const popover = (res) => {
} else if (res.status_code === 1) {
/** 查询单词或单词的其他操作失败*/
// 查询正常,但是没有这个单词
document.querySelector('#shanbay-popover .popover-inner').innerHTML = '<div class="popover-title" style="border: none;">没有找到这个单词</div>'
document.querySelector('#shanbay-popover #shanbay-inner').innerHTML = '<div id="shanbay-title" style="border: none;">没有找到这个单词</div>'
} else {
/** 未预料的状态*/
let m = 'unHandle response!!! Please tell <a href="https://github.com/maicss/chrome-shanbay-v2/issues">me</a> which word you lookup, thanks.'
document.querySelector('#shanbay-popover .popover-title').innerHTML = m
let m = '哇塞,非常罕见的错误哎,请 <a href="https://github.com/maicss/chrome-shanbay-v2/issues">告诉我</a>你怎么发现这个错误的。我会尽快处理的,嗯嗯。'
document.querySelector('#shanbay-popover #shanbay-title').innerHTML = m
console.error(m, JSON.stringify(res))
}
}
Expand Down
4 changes: 2 additions & 2 deletions manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"content_scripts": [
{
"css": [
"css/popup.css"
"css/popover.css"
],
"js": [
"js/const.js",
Expand All @@ -44,7 +44,7 @@
"js/const.js",
"js/github-avatar.js"
],
"matches": ["https://github.com/"]
"matches": ["https://github.com/*"]
}
],
"permissions": [
Expand Down

0 comments on commit 550bd5c

Please sign in to comment.