Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A few changes related to language #270

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
11 changes: 7 additions & 4 deletions dist/debugHelper.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// ==UserScript==
// @name 油猴调试助手
// @name h5player DebugHelper
// @name:en h5player DebugHelper
// @name:zh 油猴调试助手
// @namespace https://github.com/xxxily/TampermonkeyDebugHelper
// @version 0.0.1
// @description 用于油猴脚本的本地开发调试使用
// @description Used for local development and debugging of TamperMonkey script
// @description:zh 用于油猴脚本的本地开发调试使用
// @author xxxily
// @match http://*/*
// @match https://*/*
Expand Down Expand Up @@ -113,10 +116,10 @@ const _debugTools_ = {
const t = this
return new Promise((resolve, reject) => {
t.get(scriptUrl + '?t=' + Date.now()).catch(err => {
console.log('脚本内容加载出错~')
console.log('脚本内容加载出错~ / Error loading script <' + scriptUrl + '>')
resolve('')
}).then(res => {
console.log('脚本内容更新成功~')
console.log('脚本内容更新成功~ / Script <' + scriptUrl + '> was updated successfully')
if (saveToNamespace) {
window.GM_setValue(saveToNamespace, res.responseText)
}
Expand Down
4 changes: 2 additions & 2 deletions src/h5player/comment.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// ==UserScript==
// @name HTML5视频播放器增强脚本
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be side effects of changing the official name. Possibly TM or GreasyFork might think it's a new script, rather than a change to the existing one.
https://greasyfork.org/en/discussions/greasyfork/75556-when-a-script-name-is-changed-greasyfork-doesn-t-recognize-the-old-script
This needs to be well tested. Changing description and other things should be safe and could be first step.

// @name HTML5 video player enhanced script
// @name:en HTML5 video player enhanced script
// @name:zh HTML5视频播放器增强脚本
// @name:zh-TW HTML5視頻播放器增強腳本
Expand All @@ -10,7 +10,7 @@
// @namespace https://github.com/xxxily/h5player
// @homepage https://github.com/xxxily/h5player
// @version 3.3.9
// @description HTML5视频播放增强脚本,支持所有H5视频播放网站,全程快捷键控制,支持:倍速播放/加速播放、视频画面截图、画中画、网页全屏、调节亮度、饱和度、对比度、自定义配置功能增强等功能。
// @description HTML5 video playback enhanced script, supports all H5 video playback websites, full-length shortcut key control, supports: double-speed playback / accelerated playback, video screenshots, picture-in-picture, full-page webpage, brightness, saturation, contrast, custom configuration enhancement And other functions.
// @description:en HTML5 video playback enhanced script, supports all H5 video playback websites, full-length shortcut key control, supports: double-speed playback / accelerated playback, video screenshots, picture-in-picture, full-page webpage, brightness, saturation, contrast, custom configuration enhancement And other functions.
// @description:zh HTML5视频播放增强脚本,支持所有H5视频播放网站,全程快捷键控制,支持:倍速播放/加速播放、视频画面截图、画中画、网页全屏、调节亮度、饱和度、对比度、自定义配置功能增强等功能。
// @description:zh-TW HTML5視頻播放增強腳本,支持所有H5視頻播放網站,全程快捷鍵控制,支持:倍速播放/加速播放、視頻畫面截圖、畫中畫、網頁全屏、調節亮度、飽和度、對比度、自定義配置功能增強等功能。
Expand Down
2 changes: 2 additions & 0 deletions src/h5player/h5PlayerTccInit.js
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,8 @@ function h5PlayerTccInit (h5Player) {
return task(h5Player, taskConf, data)
} catch (e) {
console.error('TCC自定义函数任务执行失败:', h5Player, taskConf, data)
console.error('TCC fail:', e)
h5Player.tipsI('tipsMsg.configError', taskName)
return false
}
} else {
Expand Down
8 changes: 8 additions & 0 deletions src/h5player/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -666,6 +666,13 @@ const originalMethods = {

return tispContainer
},
tipsI: function (...strs) {
const t = h5Player
let out = strs
out = out.map(s => i18n.t(s) || s)
out = out.join('')
return t.tips(out)
},
tips: function (str) {
const t = h5Player
const player = t.player()
Expand Down Expand Up @@ -1288,6 +1295,7 @@ const originalMethods = {
if (!curTime || Number.isNaN(curTime)) return

if (t.isAllowRestorePlayProgress()) {
debug.log('playbackrestored:', curTime, 'from', player.currentTime)
player.currentTime = curTime || player.currentTime
if (curTime > 3) {
t.tips(i18n.t('tipsMsg.playbackrestored'))
Expand Down
1 change: 1 addition & 0 deletions src/h5player/locale/core-lang/en-US.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export default {
donate: 'donate',
disableInitAutoPlay: 'Prohibit autoplay of videos on this site',
tipsMsg: {
configError: 'Exception for this config in function: ',
playspeed: 'Speed: ',
forward: 'Forward: ',
backward: 'Backward: ',
Expand Down
27 changes: 22 additions & 5 deletions src/libs/I18n/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class I18n {
/* 指定当前要是使用的语言环境,默认无需指定,会自动读取 */
t._languages = config.languages || t._languages
t._defaultLanguage = config.defaultLanguage || t._defaultLanguage
t.changeLanguage(t._locale)
}

use () {}
Expand All @@ -44,12 +45,25 @@ class I18n {
}

changeLanguage (locale) {
if (this._languages[locale]) {
this._languages = locale
return locale
var fallback = this._languages[locale]
// alias is a string language name instead of a map
if (typeof fallback !== 'string') fallback = locale
// if found, assume a map
if (this._languages[fallback]) {
this._locale = fallback
console.log('Lang set:', this._locale)
return this._locale
}
// if lang-REGION, try lang only
fallback = fallback.split('-')
fallback = fallback.length > 0 && fallback[0]
if (fallback && this._languages[fallback]) {
this._locale = fallback
} else {
return false
this._locale = this._defaultLanguage
}
console.log('Lang set:', this._locale, 'Not available:', locale)
return this._locale
}

/**
Expand All @@ -59,7 +73,10 @@ class I18n {
* @returns {*}
*/
getValByPath (obj, path) {
path = path || ''
/* No need to check, if not a string */
if (typeof path !== 'string') return ''
if (!path) return ''

const pathArr = path.split('.')
let result = obj

Expand Down