mirror of
https://github.com/mashirozx/sakura.git
synced 2024-11-22 06:48:12 +08:00
imgur upload support
This commit is contained in:
parent
c3a0d671ed
commit
89656306f4
@ -27,8 +27,6 @@ if ( !function_exists( 'optionsframework_init' ) ) {
|
|||||||
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
|
define( 'OPTIONS_FRAMEWORK_DIRECTORY', get_template_directory_uri() . '/inc/' );
|
||||||
require_once dirname( __FILE__ ) . '/inc/options-framework.php';
|
require_once dirname( __FILE__ ) . '/inc/options-framework.php';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
function akina_setup() {
|
function akina_setup() {
|
||||||
/*
|
/*
|
||||||
@ -214,6 +212,7 @@ add_action( 'wp_enqueue_scripts', 'sakura_scripts' );
|
|||||||
*/
|
*/
|
||||||
require get_template_directory() .'/inc/decorate.php';
|
require get_template_directory() .'/inc/decorate.php';
|
||||||
require get_template_directory() .'/inc/swicher.php';
|
require get_template_directory() .'/inc/swicher.php';
|
||||||
|
require get_template_directory() .'/inc/api.php';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Custom template tags for this theme.
|
* Custom template tags for this theme.
|
||||||
@ -1633,68 +1632,6 @@ add_action( 'pre_get_posts', function( $q ){
|
|||||||
$q->set( 'post__not_in', get_option( 'sticky_posts' ) );
|
$q->set( 'post__not_in', get_option( 'sticky_posts' ) );
|
||||||
});
|
});
|
||||||
|
|
||||||
/*
|
|
||||||
* 定制实时搜索 rest api
|
|
||||||
* @rest api接口路径:https://sakura.2heng.xin/wp-json/cache_search/v1/json/
|
|
||||||
* @可在cache_search_json()函数末尾通过设置 HTTP header 控制 json 缓存时间
|
|
||||||
*/
|
|
||||||
function cache_search_json() {
|
|
||||||
$vowels = array("[", "{","]","}","<",">","\r\n", "\r", "\n","-","'",'"','`'," ",":",";",'\\'," ","toc");
|
|
||||||
$regex = <<<EOS
|
|
||||||
/<\/?[a-zA-Z]+("[^"]*"|'[^']*'|[^'">])*>|begin[\S\s]*\/begin|hermit[\S\s]*\/hermit|img[\S\s]*\/img|{{.*?}}|:.*?:/m
|
|
||||||
EOS;
|
|
||||||
|
|
||||||
$posts = new WP_Query('posts_per_page=-1&post_status=publish&post_type=post');
|
|
||||||
while ($posts->have_posts()) : $posts->the_post();
|
|
||||||
$output .= '{"type":"post","link":"'.get_post_permalink().'","title":'.json_encode(get_the_title()).',"comments":"'.get_comments_number('0', '1', '%').'","text":'.json_encode(str_replace($vowels, " ",preg_replace($regex,' ',get_the_content()))).'},';
|
|
||||||
endwhile;
|
|
||||||
wp_reset_postdata();
|
|
||||||
|
|
||||||
$pages = get_pages();
|
|
||||||
foreach ($pages as $page) {
|
|
||||||
$output .= '{"type":"page","link":"'.get_page_link($page).'","title":'.json_encode($page->post_title).',"comments":"'.$page->comment_count.'","text":'.json_encode(str_replace($vowels, " ",preg_replace($regex,' ',$page->post_content))).'},';
|
|
||||||
}
|
|
||||||
|
|
||||||
$tags = get_tags();
|
|
||||||
foreach ($tags as $tag) {
|
|
||||||
$output .= '{"type":"tag","link":"'.get_term_link($tag).'","title":'.json_encode($tag->name).',"comments":"","text":""},';
|
|
||||||
}
|
|
||||||
|
|
||||||
$categories = get_categories();
|
|
||||||
foreach ($categories as $category) {
|
|
||||||
$output .= '{"type":"category","link":"'.get_term_link($category).'","title":'.json_encode($category->name).',"comments":"","text":""},';
|
|
||||||
}
|
|
||||||
if(akina_option('live_search_comment')){
|
|
||||||
$comments = get_comments();
|
|
||||||
foreach ($comments as $comment) {
|
|
||||||
$is_private = get_comment_meta($comment->comment_ID, '_private', true);
|
|
||||||
if($is_private){
|
|
||||||
$output .= '{"type":"comment","link":"'.get_comment_link($comment).'","title":'.json_encode(get_the_title($comment->comment_post_ID)).',"comments":"","text":'.json_encode($comment->comment_author.":".__("The comment is private","sakura")/*该评论为私密评论*/).'},';
|
|
||||||
continue;
|
|
||||||
}else{
|
|
||||||
$output .= '{"type":"comment","link":"'.get_comment_link($comment).'","title":'.json_encode(get_the_title($comment->comment_post_ID)).',"comments":"","text":'.json_encode(str_replace($vowels, " ",preg_replace($regex," ",$comment->comment_author.":".$comment->comment_content))).'},';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$output = substr($output,0,strlen($output)-1);
|
|
||||||
|
|
||||||
$data = '['.$output.']';
|
|
||||||
$result = new WP_REST_Response(json_decode($data), 200);
|
|
||||||
$result->set_headers(array('Content-Type' => 'application/json',
|
|
||||||
'Cache-Control' => 'max-age=3600')); // json 缓存控制
|
|
||||||
|
|
||||||
return $result;
|
|
||||||
}
|
|
||||||
if(akina_option('live_search')){
|
|
||||||
add_action( 'rest_api_init', function () {
|
|
||||||
register_rest_route( 'cache_search/v1', '/json/', array(
|
|
||||||
'methods' => 'GET',
|
|
||||||
'callback' => 'cache_search_json',
|
|
||||||
) );
|
|
||||||
} );
|
|
||||||
}
|
|
||||||
|
|
||||||
//评论回复
|
//评论回复
|
||||||
function sakura_comment_notify($comment_id){
|
function sakura_comment_notify($comment_id){
|
||||||
if ( !$_POST['mail-notify'] )
|
if ( !$_POST['mail-notify'] )
|
||||||
@ -1702,4 +1639,4 @@ function sakura_comment_notify($comment_id){
|
|||||||
}
|
}
|
||||||
add_action('comment_post', 'sakura_comment_notify');
|
add_action('comment_post', 'sakura_comment_notify');
|
||||||
|
|
||||||
//code end
|
//code end
|
177
inc/api.php
Normal file
177
inc/api.php
Normal file
@ -0,0 +1,177 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Router
|
||||||
|
*/
|
||||||
|
add_action('rest_api_init', function () {
|
||||||
|
register_rest_route('sakura/v1', '/image/upload', array(
|
||||||
|
'methods' => 'POST',
|
||||||
|
'callback' => 'upload_image',
|
||||||
|
));
|
||||||
|
register_rest_route('sakura/v1', '/cache_search/json', array(
|
||||||
|
'methods' => 'GET',
|
||||||
|
'callback' => 'cache_search_json',
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Image uploader response
|
||||||
|
*/
|
||||||
|
function upload_image(WP_REST_Request $req)
|
||||||
|
{
|
||||||
|
// see: https://developer.wordpress.org/rest-api/requests/
|
||||||
|
|
||||||
|
// handle file params $file === $_FILES
|
||||||
|
/**
|
||||||
|
* curl \
|
||||||
|
* -F "filecomment=This is an img file" \
|
||||||
|
* -F "cmt_img_file=@screenshot.jpg" \
|
||||||
|
* https://dev.2heng.xin/wp-json/sakura/v1/image/upload
|
||||||
|
*/
|
||||||
|
$file = $req->get_file_params();
|
||||||
|
$image = file_get_contents($_FILES["cmt_img_file"]["tmp_name"]);
|
||||||
|
|
||||||
|
switch (akina_option("img_upload_api")) {
|
||||||
|
case 'imgur':
|
||||||
|
$API_Request = Imgur_API($image);
|
||||||
|
break;
|
||||||
|
case 'smms':
|
||||||
|
$API_Request = SMMS_API($image);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$result = new WP_REST_Response($API_Request, 200);
|
||||||
|
$result->set_headers(array('Content-Type' => 'application/json',
|
||||||
|
'Cache-Control' => 'max-age=3600')); // json 缓存控制
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Imgur upload interface
|
||||||
|
*/
|
||||||
|
function Imgur_API($image)
|
||||||
|
{
|
||||||
|
$client_id = akina_option('imgur_client_id');
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, akina_option('imgur_upload_image_proxy'));
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
|
||||||
|
|
||||||
|
$reply = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$reply = json_decode($reply);
|
||||||
|
|
||||||
|
if ($reply->success && $reply->status == 200) {
|
||||||
|
$status = 200;
|
||||||
|
$message = "success";
|
||||||
|
$link = $reply->data->link;
|
||||||
|
$proxy = akina_option('cmt_image_proxy') . $link;
|
||||||
|
} else {
|
||||||
|
$status = $reply->status;
|
||||||
|
$message = $reply->data->error;
|
||||||
|
$link = 'https://view.moezx.cc/images/2019/10/28/default_d_h_large.gif';
|
||||||
|
$proxy = akina_option('cmt_image_proxy') . $link;
|
||||||
|
}
|
||||||
|
$output = array(
|
||||||
|
'status' => $status,
|
||||||
|
'message' => $message,
|
||||||
|
'link' => $link,
|
||||||
|
'proxy' => $proxy,
|
||||||
|
);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
function SMMS_API($image)
|
||||||
|
{
|
||||||
|
$client_id = akina_option('smms_client_id');
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://sm.ms/api/v2/upload');
|
||||||
|
curl_setopt($ch, CURLOPT_POST, true);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Basic ' . $client_id));
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type ' . 'multipart/form-data'));
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, array('smfile' => $image));
|
||||||
|
|
||||||
|
$reply = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$reply = json_decode($reply);
|
||||||
|
|
||||||
|
if ($reply->success && $reply->code == 'success') {
|
||||||
|
$status = 200;
|
||||||
|
$message = $reply->message;
|
||||||
|
$link = $reply->data->url;
|
||||||
|
$proxy = akina_option('cmt_image_proxy') . $link;
|
||||||
|
} else {
|
||||||
|
$status = 0; // sm.ms 接口不规范,谁给提个意见?我要状态码!
|
||||||
|
$message = $reply->message;
|
||||||
|
$link = 'https://view.moezx.cc/images/2019/10/28/default_d_h_large.gif';
|
||||||
|
$proxy = akina_option('cmt_image_proxy') . $link;
|
||||||
|
}
|
||||||
|
$output = array('status' => $status,
|
||||||
|
'message' => $message,
|
||||||
|
'link' => $link,
|
||||||
|
'proxy' => $proxy,
|
||||||
|
);
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* 定制实时搜索 rest api
|
||||||
|
* @rest api接口路径:https://sakura.2heng.xin/wp-json/cache_search/v1/json/
|
||||||
|
* @可在cache_search_json()函数末尾通过设置 HTTP header 控制 json 缓存时间
|
||||||
|
*/
|
||||||
|
function cache_search_json()
|
||||||
|
{
|
||||||
|
$vowels = array("[", "{", "]", "}", "<", ">", "\r\n", "\r", "\n", "-", "'", '"', '`', " ", ":", ";", '\\', " ", "toc");
|
||||||
|
$regex = <<<EOS
|
||||||
|
/<\/?[a-zA-Z]+("[^"]*"|'[^']*'|[^'">])*>|begin[\S\s]*\/begin|hermit[\S\s]*\/hermit|img[\S\s]*\/img|{{.*?}}|:.*?:/m
|
||||||
|
EOS;
|
||||||
|
|
||||||
|
$posts = new WP_Query('posts_per_page=-1&post_status=publish&post_type=post');
|
||||||
|
while ($posts->have_posts()): $posts->the_post();
|
||||||
|
$output .= '{"type":"post","link":"' . get_post_permalink() . '","title":' . json_encode(get_the_title()) . ',"comments":"' . get_comments_number('0', '1', '%') . '","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, ' ', get_the_content()))) . '},';
|
||||||
|
endwhile;
|
||||||
|
wp_reset_postdata();
|
||||||
|
|
||||||
|
$pages = get_pages();
|
||||||
|
foreach ($pages as $page) {
|
||||||
|
$output .= '{"type":"page","link":"' . get_page_link($page) . '","title":' . json_encode($page->post_title) . ',"comments":"' . $page->comment_count . '","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, ' ', $page->post_content))) . '},';
|
||||||
|
}
|
||||||
|
|
||||||
|
$tags = get_tags();
|
||||||
|
foreach ($tags as $tag) {
|
||||||
|
$output .= '{"type":"tag","link":"' . get_term_link($tag) . '","title":' . json_encode($tag->name) . ',"comments":"","text":""},';
|
||||||
|
}
|
||||||
|
|
||||||
|
$categories = get_categories();
|
||||||
|
foreach ($categories as $category) {
|
||||||
|
$output .= '{"type":"category","link":"' . get_term_link($category) . '","title":' . json_encode($category->name) . ',"comments":"","text":""},';
|
||||||
|
}
|
||||||
|
if (akina_option('live_search_comment')) {
|
||||||
|
$comments = get_comments();
|
||||||
|
foreach ($comments as $comment) {
|
||||||
|
$is_private = get_comment_meta($comment->comment_ID, '_private', true);
|
||||||
|
if ($is_private) {
|
||||||
|
$output .= '{"type":"comment","link":"' . get_comment_link($comment) . '","title":' . json_encode(get_the_title($comment->comment_post_ID)) . ',"comments":"","text":' . json_encode($comment->comment_author . ":" . __("The comment is private", "sakura") /*该评论为私密评论*/) . '},';
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
$output .= '{"type":"comment","link":"' . get_comment_link($comment) . '","title":' . json_encode(get_the_title($comment->comment_post_ID)) . ',"comments":"","text":' . json_encode(str_replace($vowels, " ", preg_replace($regex, " ", $comment->comment_author . ":" . $comment->comment_content))) . '},';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$output = substr($output, 0, strlen($output) - 1);
|
||||||
|
|
||||||
|
$data = '[' . $output . ']';
|
||||||
|
$result = new WP_REST_Response(json_decode($data), 200);
|
||||||
|
$result->set_headers(array('Content-Type' => 'application/json',
|
||||||
|
'Cache-Control' => 'max-age=3600')); // json 缓存控制
|
||||||
|
|
||||||
|
return $result;
|
||||||
|
}
|
BIN
inc/test.jpg
Normal file
BIN
inc/test.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 32 KiB |
31
inc/test.php
Normal file
31
inc/test.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
ini_set('display_errors', 1);
|
||||||
|
ini_set('display_startup_errors', 1);
|
||||||
|
error_reporting(E_ALL);
|
||||||
|
|
||||||
|
$image = file_get_contents("test.jpg");
|
||||||
|
|
||||||
|
function Imgur_API($image) {
|
||||||
|
$client_id = "98cd21cdfc58130";
|
||||||
|
|
||||||
|
$ch = curl_init();
|
||||||
|
curl_setopt($ch, CURLOPT_URL, 'https://api.mashiro.top/imgur-api/3/image');
|
||||||
|
curl_setopt($ch, CURLOPT_POST, TRUE);
|
||||||
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
||||||
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: Client-ID ' . $client_id));
|
||||||
|
curl_setopt($ch, CURLOPT_POSTFIELDS, array('image' => base64_encode($image)));
|
||||||
|
|
||||||
|
$reply = curl_exec($ch);
|
||||||
|
curl_close($ch);
|
||||||
|
|
||||||
|
$reply = json_decode($reply);
|
||||||
|
var_dump($reply);
|
||||||
|
printf('<img height="180" src="%s" >', $reply->data->link);
|
||||||
|
$res = $reply->data->link;
|
||||||
|
$res = 'https://images.weserv.nl/?url='.$res;
|
||||||
|
echo $res;
|
||||||
|
printf('<img height="180" src="%s" >', $res);
|
||||||
|
}
|
||||||
|
|
||||||
|
Imgur_API($image);
|
367
js/sakura-app.js
367
js/sakura-app.js
@ -63,7 +63,7 @@ function imgError(ele, type) {
|
|||||||
default:
|
default:
|
||||||
ele.src = 'https://view.moezx.cc/images/2018/05/13/image-404.png';
|
ele.src = 'https://view.moezx.cc/images/2018/05/13/image-404.png';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function post_list_show_animation() {
|
function post_list_show_animation() {
|
||||||
if ($("article").hasClass("post-list-thumb")) {
|
if ($("article").hasClass("post-list-thumb")) {
|
||||||
@ -73,6 +73,7 @@ function post_list_show_animation() {
|
|||||||
}
|
}
|
||||||
var io = new IntersectionObserver(callback, options);
|
var io = new IntersectionObserver(callback, options);
|
||||||
var articles = document.querySelectorAll('.post-list-thumb');
|
var articles = document.querySelectorAll('.post-list-thumb');
|
||||||
|
|
||||||
function callback(entries) {
|
function callback(entries) {
|
||||||
entries.forEach((article) => {
|
entries.forEach((article) => {
|
||||||
if (article.target.classList.contains("post-list-show")) {
|
if (article.target.classList.contains("post-list-show")) {
|
||||||
@ -157,9 +158,9 @@ try {
|
|||||||
code_highlight_style();
|
code_highlight_style();
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
|
|
||||||
if (Poi.reply_link_version == 'new'){
|
if (Poi.reply_link_version == 'new') {
|
||||||
$('body').on('click','.comment-reply-link',function(){
|
$('body').on('click', '.comment-reply-link', function () {
|
||||||
addComment.moveForm( "comment-"+$(this).attr('data-commentid'), $(this).attr('data-commentid'), "respond", $(this).attr('data-postid') );
|
addComment.moveForm("comment-" + $(this).attr('data-commentid'), $(this).attr('data-commentid'), "respond", $(this).attr('data-postid'));
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -179,9 +180,9 @@ function attach_image() {
|
|||||||
for (var i = 0; i < this.files.length; i++) {
|
for (var i = 0; i < this.files.length; i++) {
|
||||||
var f = this.files[i];
|
var f = this.files[i];
|
||||||
var formData = new FormData();
|
var formData = new FormData();
|
||||||
formData.append('smfile', f);
|
formData.append('cmt_img_file', f);
|
||||||
$.ajax({
|
$.ajax({
|
||||||
url: 'https://sm.ms/api/upload',
|
url: '/wp-json/sakura/v1/image/upload',
|
||||||
type: 'POST',
|
type: 'POST',
|
||||||
processData: false,
|
processData: false,
|
||||||
contentType: false,
|
contentType: false,
|
||||||
@ -195,18 +196,24 @@ function attach_image() {
|
|||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
cached.html('<i class="fa fa-picture-o" aria-hidden="true"></i>');
|
cached.html('<i class="fa fa-picture-o" aria-hidden="true"></i>');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
var get_the_url = res.data.url;
|
var get_the_url = res.proxy;
|
||||||
$('#upload-img-show').append('<img class="lazyload upload-image-preview" src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.0.2/img/svg/loader/trans.ajax-spinner-preloader.svg" data-src="' + get_the_url + '" onclick="window.open(\'' + get_the_url + '\')" onerror="imgError(this)" />');
|
$('#upload-img-show').append('<img class="lazyload upload-image-preview" src="https://cdn.jsdelivr.net/gh/moezx/cdn@3.0.2/img/svg/loader/trans.ajax-spinner-preloader.svg" data-src="' + get_the_url + '" onclick="window.open(\'' + get_the_url + '\')" onerror="imgError(this)" />');
|
||||||
lazyload();
|
lazyload();
|
||||||
addComment.createButterbar("图片上传成功~<br>Uploaded successfully~");
|
addComment.createButterbar("图片上传成功~<br>Uploaded successfully~");
|
||||||
grin(res.data.url.replace('https://i.loli.net/', '{UPLOAD}'), type = 'Img');
|
grin(get_the_url, type = 'Img');
|
||||||
},
|
},
|
||||||
error: function () {
|
error: function (jqXHR, textStatus, errorThrown) {
|
||||||
cached.html('<i class="fa fa-times" aria-hidden="true" style="color:red"></i>');
|
cached.html('<i class="fa fa-times" aria-hidden="true" style="color:red"></i>');
|
||||||
alert("上传失败,请重试.\nUpload failed, please try again.");
|
alert("上传失败,请重试.\nUpload failed, please try again.");
|
||||||
setTimeout(function () {
|
setTimeout(function () {
|
||||||
cached.html('<i class="fa fa-picture-o" aria-hidden="true"></i>');
|
cached.html('<i class="fa fa-picture-o" aria-hidden="true"></i>');
|
||||||
}, 1000);
|
}, 1000);
|
||||||
|
// console.info(jqXHR.responseText);
|
||||||
|
// console.info(jqXHR.status);
|
||||||
|
// console.info(jqXHR.readyState);
|
||||||
|
// console.info(jqXHR.statusText);
|
||||||
|
// console.info(textStatus);
|
||||||
|
// console.info(errorThrown);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -297,6 +304,7 @@ function checkskinSecter() {
|
|||||||
$(".headertop-bar-sakura").removeClass('headertop-bar-sakura').addClass('headertop-bar');
|
$(".headertop-bar-sakura").removeClass('headertop-bar-sakura').addClass('headertop-bar');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkBgImgCookie() {
|
function checkBgImgCookie() {
|
||||||
var bgurl = getCookie("bgImgSetting");
|
var bgurl = getCookie("bgImgSetting");
|
||||||
if (!bgurl) {
|
if (!bgurl) {
|
||||||
@ -306,7 +314,7 @@ function checkBgImgCookie() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (document.body.clientWidth > 860) {
|
if (document.body.clientWidth > 860) {
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
checkBgImgCookie();
|
checkBgImgCookie();
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
@ -317,15 +325,16 @@ function no_right_click() {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
no_right_click();
|
no_right_click();
|
||||||
$(document).ready(function() {
|
$(document).ready(function () {
|
||||||
function checkskin_bg(a){
|
function checkskin_bg(a) {
|
||||||
return a == "none" ? "" : a
|
return a == "none" ? "" : a
|
||||||
}
|
}
|
||||||
|
|
||||||
function changeBG() {
|
function changeBG() {
|
||||||
var cached=$(".menu-list");
|
var cached = $(".menu-list");
|
||||||
cached.find("li").each(function() {
|
cached.find("li").each(function () {
|
||||||
var tagid = this.id;
|
var tagid = this.id;
|
||||||
cached.on("click", "#" + tagid, function(){
|
cached.on("click", "#" + tagid, function () {
|
||||||
if (tagid == "white-bg") {
|
if (tagid == "white-bg") {
|
||||||
mashiro_global.variables.skinSecter = true;
|
mashiro_global.variables.skinSecter = true;
|
||||||
checkskinSecter();
|
checkskinSecter();
|
||||||
@ -372,14 +381,14 @@ $(document).ready(function() {
|
|||||||
|
|
||||||
function closeSkinMenu() {
|
function closeSkinMenu() {
|
||||||
$(".skin-menu").removeClass('show');
|
$(".skin-menu").removeClass('show');
|
||||||
setTimeout(function() {
|
setTimeout(function () {
|
||||||
$(".changeSkin-gear").css("visibility", "visible");
|
$(".changeSkin-gear").css("visibility", "visible");
|
||||||
}, 300);
|
}, 300);
|
||||||
}
|
}
|
||||||
$(".changeSkin-gear").click(function() {
|
$(".changeSkin-gear").click(function () {
|
||||||
$(".skin-menu").toggleClass('show');
|
$(".skin-menu").toggleClass('show');
|
||||||
})
|
})
|
||||||
$(".skin-menu #close-skinMenu").click(function() {
|
$(".skin-menu #close-skinMenu").click(function () {
|
||||||
closeSkinMenu();
|
closeSkinMenu();
|
||||||
});
|
});
|
||||||
add_upload_tips();
|
add_upload_tips();
|
||||||
@ -514,16 +523,16 @@ function coverVideoIni() {
|
|||||||
if ($('video').hasClass('hls')) {
|
if ($('video').hasClass('hls')) {
|
||||||
var video = addComment.I('coverVideo');
|
var video = addComment.I('coverVideo');
|
||||||
var video_src = $('#coverVideo').attr('data-src');
|
var video_src = $('#coverVideo').attr('data-src');
|
||||||
if(Hls.isSupported()) {
|
if (Hls.isSupported()) {
|
||||||
var hls = new Hls();
|
var hls = new Hls();
|
||||||
hls.loadSource(video_src);
|
hls.loadSource(video_src);
|
||||||
hls.attachMedia(video);
|
hls.attachMedia(video);
|
||||||
hls.on(Hls.Events.MANIFEST_PARSED,function() {
|
hls.on(Hls.Events.MANIFEST_PARSED, function () {
|
||||||
video.play();
|
video.play();
|
||||||
});
|
});
|
||||||
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
} else if (video.canPlayType('application/vnd.apple.mpegurl')) {
|
||||||
video.src = video_src;
|
video.src = video_src;
|
||||||
video.addEventListener('loadedmetadata',function() {
|
video.addEventListener('loadedmetadata', function () {
|
||||||
video.play();
|
video.play();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -533,7 +542,9 @@ function coverVideoIni() {
|
|||||||
|
|
||||||
function copy_code_block() {
|
function copy_code_block() {
|
||||||
$('pre code').each(function (i, block) {
|
$('pre code').each(function (i, block) {
|
||||||
$(block).attr({ id: 'hljs-' + i });
|
$(block).attr({
|
||||||
|
id: 'hljs-' + i
|
||||||
|
});
|
||||||
$(this).after('<a class="copy-code" href="javascript:" data-clipboard-target="#hljs-' + i + '" title="拷贝代码"><i class="fa fa-clipboard" aria-hidden="true"></i></a>');
|
$(this).after('<a class="copy-code" href="javascript:" data-clipboard-target="#hljs-' + i + '" title="拷贝代码"><i class="fa fa-clipboard" aria-hidden="true"></i></a>');
|
||||||
});
|
});
|
||||||
var clipboard = new ClipboardJS('.copy-code');
|
var clipboard = new ClipboardJS('.copy-code');
|
||||||
@ -548,7 +559,7 @@ function tableOfContentScroll(flag) {
|
|||||||
if (flag) {
|
if (flag) {
|
||||||
var id = 1,
|
var id = 1,
|
||||||
heading_fix = mashiro_option.entry_content_theme == "sakura" ? $("article").hasClass("type-post") ? $("div").hasClass("pattern-attachment-img") ? -75 : 200 : 375 : window.innerHeight / 2;
|
heading_fix = mashiro_option.entry_content_theme == "sakura" ? $("article").hasClass("type-post") ? $("div").hasClass("pattern-attachment-img") ? -75 : 200 : 375 : window.innerHeight / 2;
|
||||||
$(".entry-content , .links").children("h1,h2,h3,h4,h5").each(function() {
|
$(".entry-content , .links").children("h1,h2,h3,h4,h5").each(function () {
|
||||||
var hyphenated = "toc-head-" + id;
|
var hyphenated = "toc-head-" + id;
|
||||||
this.id = hyphenated;
|
this.id = hyphenated;
|
||||||
id++;
|
id++;
|
||||||
@ -557,7 +568,7 @@ function tableOfContentScroll(flag) {
|
|||||||
tocSelector: '.toc',
|
tocSelector: '.toc',
|
||||||
contentSelector: ['.entry-content', '.links'],
|
contentSelector: ['.entry-content', '.links'],
|
||||||
headingSelector: 'h1, h2, h3, h4, h5',
|
headingSelector: 'h1, h2, h3, h4, h5',
|
||||||
headingsOffset: heading_fix-window.innerHeight/2,
|
headingsOffset: heading_fix - window.innerHeight / 2,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -722,7 +733,7 @@ $(function () {
|
|||||||
getqqinfo();
|
getqqinfo();
|
||||||
});
|
});
|
||||||
|
|
||||||
if(mashiro_option.float_player_on) {
|
if (mashiro_option.float_player_on) {
|
||||||
function aplayerF() {
|
function aplayerF() {
|
||||||
'use strict';
|
'use strict';
|
||||||
var aplayers = [],
|
var aplayers = [],
|
||||||
@ -761,7 +772,7 @@ if(mashiro_option.float_player_on) {
|
|||||||
console.log(a)
|
console.log(a)
|
||||||
}
|
}
|
||||||
var lrcTag = 1;
|
var lrcTag = 1;
|
||||||
$(".aplayer.aplayer-fixed").click(function(){
|
$(".aplayer.aplayer-fixed").click(function () {
|
||||||
if (lrcTag == 1) {
|
if (lrcTag == 1) {
|
||||||
for (var f = 0; f < aplayers.length; f++) try {
|
for (var f = 0; f < aplayers.length; f++) try {
|
||||||
aplayers[f].lrc.show();
|
aplayers[f].lrc.show();
|
||||||
@ -772,18 +783,24 @@ if(mashiro_option.float_player_on) {
|
|||||||
lrcTag = 2;
|
lrcTag = 2;
|
||||||
});
|
});
|
||||||
var apSwitchTag = 0;
|
var apSwitchTag = 0;
|
||||||
var aplayerlist=$(".aplayer-list");
|
var aplayerlist = $(".aplayer-list");
|
||||||
aplayerlist.removeClass( "aplayer-list-hide" ).css({maxHeight:'0px'});
|
aplayerlist.removeClass("aplayer-list-hide").css({
|
||||||
|
maxHeight: '0px'
|
||||||
|
});
|
||||||
$(".aplayer.aplayer-fixed .aplayer-body").addClass("ap-hover");
|
$(".aplayer.aplayer-fixed .aplayer-body").addClass("ap-hover");
|
||||||
$(".aplayer-miniswitcher").click(function(){
|
$(".aplayer-miniswitcher").click(function () {
|
||||||
if (apSwitchTag == 0) {
|
if (apSwitchTag == 0) {
|
||||||
aplayerlist.removeClass( "aplayer-list-hide" ).animate({maxHeight:'250px'});
|
aplayerlist.removeClass("aplayer-list-hide").animate({
|
||||||
$(".aplayer.aplayer-fixed .aplayer-body").removeClass( "ap-hover" );
|
maxHeight: '250px'
|
||||||
|
});
|
||||||
|
$(".aplayer.aplayer-fixed .aplayer-body").removeClass("ap-hover");
|
||||||
apSwitchTag = 1;
|
apSwitchTag = 1;
|
||||||
} else {
|
} else {
|
||||||
aplayerlist.css({maxHeight:'0px'});
|
aplayerlist.css({
|
||||||
$(".aplayer.aplayer-fixed .aplayer-body").addClass( "ap-hover" );
|
maxHeight: '0px'
|
||||||
apSwitchTag =0;
|
});
|
||||||
|
$(".aplayer.aplayer-fixed .aplayer-body").addClass("ap-hover");
|
||||||
|
apSwitchTag = 0;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -824,12 +841,13 @@ if(mashiro_option.float_player_on) {
|
|||||||
document.addEventListener('DOMContentLoaded', loadMeting, !1);
|
document.addEventListener('DOMContentLoaded', loadMeting, !1);
|
||||||
}
|
}
|
||||||
if (document.body.clientWidth > 860) {
|
if (document.body.clientWidth > 860) {
|
||||||
aplayerF ();
|
aplayerF();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function getqqinfo() {
|
function getqqinfo() {
|
||||||
var is_get_by_qq = false,cached = $('input');
|
var is_get_by_qq = false,
|
||||||
|
cached = $('input');
|
||||||
if (!getCookie('user_qq') && !getCookie('user_qq_email') && !getCookie('user_author')) {
|
if (!getCookie('user_qq') && !getCookie('user_qq_email') && !getCookie('user_author')) {
|
||||||
cached.filter('#qq,#author,#email,#url').val('');
|
cached.filter('#qq,#author,#email,#url').val('');
|
||||||
}
|
}
|
||||||
@ -1284,20 +1302,22 @@ var home = location.href,
|
|||||||
AH: function () {
|
AH: function () {
|
||||||
if (Poi.windowheight == 'auto') {
|
if (Poi.windowheight == 'auto') {
|
||||||
if ($('h1.main-title').length > 0) {
|
if ($('h1.main-title').length > 0) {
|
||||||
var _height = $(window).height()+"px";
|
var _height = $(window).height() + "px";
|
||||||
$('#centerbg').css({
|
$('#centerbg').css({
|
||||||
'height': _height
|
'height': _height
|
||||||
});
|
});
|
||||||
$('#bgvideo').css({
|
$('#bgvideo').css({
|
||||||
'min-height': _height
|
'min-height': _height
|
||||||
});
|
});
|
||||||
window.resizeFlag= null;
|
window.resizeFlag = null;
|
||||||
$(window).resize(function () {
|
$(window).resize(function () {
|
||||||
//直接resize性能爆炸,改成延时
|
//直接resize性能爆炸,改成延时
|
||||||
if(resizeFlag=null){
|
if (resizeFlag = null) {
|
||||||
clearTimeout(resizeFlag);
|
clearTimeout(resizeFlag);
|
||||||
}
|
}
|
||||||
resizeFlag = setTimeout(function(){ Siren.AH();}, 1000);
|
resizeFlag = setTimeout(function () {
|
||||||
|
Siren.AH();
|
||||||
|
}, 1000);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -1349,131 +1369,134 @@ var home = location.href,
|
|||||||
$('.js-toggle-search').on('click', function () {
|
$('.js-toggle-search').on('click', function () {
|
||||||
$('.js-toggle-search').toggleClass('is-active');
|
$('.js-toggle-search').toggleClass('is-active');
|
||||||
$('.js-search').toggleClass('is-visible');
|
$('.js-search').toggleClass('is-visible');
|
||||||
$('html').css('overflow-y','hidden');
|
$('html').css('overflow-y', 'hidden');
|
||||||
if (mashiro_option.live_search) {
|
if (mashiro_option.live_search) {
|
||||||
var QueryStorage = [];
|
var QueryStorage = [];
|
||||||
search_a("https://"+document.domain+"/wp-json/cache_search/v1/json/");
|
search_a("https://" + document.domain + "/wp-json/sakura/v1/cache_search/json");
|
||||||
|
|
||||||
var otxt = addComment.I("search-input"),
|
|
||||||
list = addComment.I("PostlistBox"),
|
|
||||||
Record = list.innerHTML,
|
|
||||||
searchFlag = null;
|
|
||||||
otxt.oninput = function () {
|
|
||||||
if(searchFlag=null){
|
|
||||||
clearTimeout(searchFlag);
|
|
||||||
}
|
|
||||||
searchFlag = setTimeout(function(){
|
|
||||||
query(QueryStorage, otxt.value, Record);
|
|
||||||
div_href();
|
|
||||||
}, 250);
|
|
||||||
};
|
|
||||||
|
|
||||||
function search_a(val) {
|
var otxt = addComment.I("search-input"),
|
||||||
if(sessionStorage.getItem('search')!=null){
|
list = addComment.I("PostlistBox"),
|
||||||
QueryStorage = JSON.parse(sessionStorage.getItem('search'));
|
Record = list.innerHTML,
|
||||||
query(QueryStorage, $("#search-input").val(), Record);
|
searchFlag = null;
|
||||||
div_href();
|
otxt.oninput = function () {
|
||||||
}else{
|
if (searchFlag = null) {
|
||||||
var _xhr = new XMLHttpRequest();
|
clearTimeout(searchFlag);
|
||||||
_xhr.open("GET", val, true)
|
}
|
||||||
_xhr.send();
|
searchFlag = setTimeout(function () {
|
||||||
_xhr.onreadystatechange = function () {
|
query(QueryStorage, otxt.value, Record);
|
||||||
if (_xhr.readyState == 4 && _xhr.status == 200) {
|
div_href();
|
||||||
json = _xhr.responseText;
|
}, 250);
|
||||||
if (json != "") {
|
};
|
||||||
sessionStorage.setItem('search',json);
|
|
||||||
QueryStorage = JSON.parse(json);
|
function search_a(val) {
|
||||||
query(QueryStorage, otxt.value, Record);
|
if (sessionStorage.getItem('search') != null) {
|
||||||
div_href();
|
QueryStorage = JSON.parse(sessionStorage.getItem('search'));
|
||||||
|
query(QueryStorage, $("#search-input").val(), Record);
|
||||||
|
div_href();
|
||||||
|
} else {
|
||||||
|
var _xhr = new XMLHttpRequest();
|
||||||
|
_xhr.open("GET", val, true)
|
||||||
|
_xhr.send();
|
||||||
|
_xhr.onreadystatechange = function () {
|
||||||
|
if (_xhr.readyState == 4 && _xhr.status == 200) {
|
||||||
|
json = _xhr.responseText;
|
||||||
|
if (json != "") {
|
||||||
|
sessionStorage.setItem('search', json);
|
||||||
|
QueryStorage = JSON.parse(json);
|
||||||
|
query(QueryStorage, otxt.value, Record);
|
||||||
|
div_href();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
if (!Object.values) Object.values = function (obj) {
|
||||||
if (!Object.values) Object.values = function (obj) {
|
if (obj !== Object(obj))
|
||||||
if (obj !== Object(obj))
|
throw new TypeError('Object.values called on a non-object');
|
||||||
throw new TypeError('Object.values called on a non-object');
|
var val = [],
|
||||||
var val = [],
|
key;
|
||||||
key;
|
for (key in obj) {
|
||||||
for (key in obj) {
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
||||||
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
val.push(obj[key]);
|
||||||
val.push(obj[key]);
|
}
|
||||||
}
|
}
|
||||||
|
return val;
|
||||||
}
|
}
|
||||||
return val;
|
|
||||||
}
|
|
||||||
function Cx(arr, q) {
|
|
||||||
q = q.replace(q,"^(?=.*?"+q+").+$").replace(/\s/g,")(?=.*?");
|
|
||||||
i = arr.filter(
|
|
||||||
v => Object.values(v).some(
|
|
||||||
v => new RegExp(q + '').test(v)
|
|
||||||
)
|
|
||||||
);
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
function div_href(){
|
|
||||||
$(".ins-selectable").each(function(){
|
|
||||||
$(this).click(function(){
|
|
||||||
$("#Ty").attr('href',$(this).attr('href'));
|
|
||||||
$("#Ty").click();
|
|
||||||
$(".search_close").click();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
|
||||||
function search_result(keyword, link, fa, title, iconfont, comments, text){
|
|
||||||
if(keyword){
|
|
||||||
var s = keyword.trim().split(" "),
|
|
||||||
a = title.indexOf(s[s.length-1]),
|
|
||||||
b = text.indexOf(s[s.length-1]);
|
|
||||||
title=a<60 ? title.slice(0,80):title.slice(a-30,a+30);
|
|
||||||
title=title.replace(s[s.length-1], '<mark class="search-keyword"> ' + s[s.length-1].toUpperCase() + ' </mark>');
|
|
||||||
text=b<60 ? text.slice(0,80):text.slice(b-30,b+30);
|
|
||||||
text=text.replace(s[s.length-1], '<mark class="search-keyword"> ' + s[s.length-1].toUpperCase() + ' </mark>');
|
|
||||||
}
|
|
||||||
return '<div class="ins-selectable ins-search-item" href="' + link + '"><header><i class="fa fa-'+ fa +'" aria-hidden="true"></i>' + title + '<i class="iconfont icon-'+ iconfont +'"> ' + comments + '</i>' + '</header><p class="ins-search-preview">' + text + '</p></div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
function query(B, A, z) {
|
function Cx(arr, q) {
|
||||||
var x, v, s, y = "",
|
q = q.replace(q, "^(?=.*?" + q + ").+$").replace(/\s/g, ")(?=.*?");
|
||||||
w = "",
|
i = arr.filter(
|
||||||
u = "",
|
v => Object.values(v).some(
|
||||||
r = "",
|
v => new RegExp(q + '').test(v)
|
||||||
p = "",
|
)
|
||||||
F = "",
|
);
|
||||||
H = "",
|
return i;
|
||||||
G = '<section class="ins-section"><header class="ins-section-header">',
|
}
|
||||||
D = "</section>",
|
|
||||||
E = "</header>",
|
function div_href() {
|
||||||
C = Cx(B, A.trim());
|
$(".ins-selectable").each(function () {
|
||||||
for (x = 0; x < Object.keys(C).length; x++) {
|
$(this).click(function () {
|
||||||
H = C[x];
|
$("#Ty").attr('href', $(this).attr('href'));
|
||||||
switch (v = H.type) {
|
$("#Ty").click();
|
||||||
case "post":
|
$(".search_close").click();
|
||||||
w = w + search_result(A, H.link, "file", H.title, "mark", H.comments, H.text);
|
});
|
||||||
break;
|
});
|
||||||
case "tag":
|
}
|
||||||
p = p + search_result("", H.link, "tag", H.title, "none", "", "");
|
|
||||||
break;
|
function search_result(keyword, link, fa, title, iconfont, comments, text) {
|
||||||
case "category":
|
if (keyword) {
|
||||||
r = r + search_result("", H.link, "folder", H.title, "none", "", "");
|
var s = keyword.trim().split(" "),
|
||||||
break;
|
a = title.indexOf(s[s.length - 1]),
|
||||||
case "page":
|
b = text.indexOf(s[s.length - 1]);
|
||||||
u = u + search_result(A, H.link, "file", H.title, "mark", H.comments, H.text);
|
title = a < 60 ? title.slice(0, 80) : title.slice(a - 30, a + 30);
|
||||||
break;
|
title = title.replace(s[s.length - 1], '<mark class="search-keyword"> ' + s[s.length - 1].toUpperCase() + ' </mark>');
|
||||||
case "comment":
|
text = b < 60 ? text.slice(0, 80) : text.slice(b - 30, b + 30);
|
||||||
F = F + search_result(A, H.link, "comment", H.title, "none", "", H.text);
|
text = text.replace(s[s.length - 1], '<mark class="search-keyword"> ' + s[s.length - 1].toUpperCase() + ' </mark>');
|
||||||
break
|
}
|
||||||
}
|
return '<div class="ins-selectable ins-search-item" href="' + link + '"><header><i class="fa fa-' + fa + '" aria-hidden="true"></i>' + title + '<i class="iconfont icon-' + iconfont + '"> ' + comments + '</i>' + '</header><p class="ins-search-preview">' + text + '</p></div>';
|
||||||
}
|
}
|
||||||
w && (y = y + G + "文章" + E + w + D), u && (y = y + G + "页面" + E + u + D), r && (y = y + G + "分类" + E + r + D), p && (y = y + G + "标签" + E + p + D), F && (y = y + G + "评论" + E + F + D), s = addComment.I("PostlistBox"), s.innerHTML = y
|
|
||||||
}
|
function query(B, A, z) {
|
||||||
|
var x, v, s, y = "",
|
||||||
|
w = "",
|
||||||
|
u = "",
|
||||||
|
r = "",
|
||||||
|
p = "",
|
||||||
|
F = "",
|
||||||
|
H = "",
|
||||||
|
G = '<section class="ins-section"><header class="ins-section-header">',
|
||||||
|
D = "</section>",
|
||||||
|
E = "</header>",
|
||||||
|
C = Cx(B, A.trim());
|
||||||
|
for (x = 0; x < Object.keys(C).length; x++) {
|
||||||
|
H = C[x];
|
||||||
|
switch (v = H.type) {
|
||||||
|
case "post":
|
||||||
|
w = w + search_result(A, H.link, "file", H.title, "mark", H.comments, H.text);
|
||||||
|
break;
|
||||||
|
case "tag":
|
||||||
|
p = p + search_result("", H.link, "tag", H.title, "none", "", "");
|
||||||
|
break;
|
||||||
|
case "category":
|
||||||
|
r = r + search_result("", H.link, "folder", H.title, "none", "", "");
|
||||||
|
break;
|
||||||
|
case "page":
|
||||||
|
u = u + search_result(A, H.link, "file", H.title, "mark", H.comments, H.text);
|
||||||
|
break;
|
||||||
|
case "comment":
|
||||||
|
F = F + search_result(A, H.link, "comment", H.title, "none", "", H.text);
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
w && (y = y + G + "文章" + E + w + D), u && (y = y + G + "页面" + E + u + D), r && (y = y + G + "分类" + E + r + D), p && (y = y + G + "标签" + E + p + D), F && (y = y + G + "评论" + E + F + D), s = addComment.I("PostlistBox"), s.innerHTML = y
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('.search_close').on('click', function () {
|
$('.search_close').on('click', function () {
|
||||||
if ($('.js-search').hasClass('is-visible')) {
|
if ($('.js-search').hasClass('is-visible')) {
|
||||||
$('.js-toggle-search').toggleClass('is-active');
|
$('.js-toggle-search').toggleClass('is-active');
|
||||||
$('.js-search').toggleClass('is-visible');
|
$('.js-search').toggleClass('is-visible');
|
||||||
$('html').css('overflow-y','unset');
|
$('html').css('overflow-y', 'unset');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#show-nav').on('click', function () {
|
$('#show-nav').on('click', function () {
|
||||||
@ -1492,7 +1515,8 @@ var home = location.href,
|
|||||||
NH: function () {
|
NH: function () {
|
||||||
var h1 = 0;
|
var h1 = 0;
|
||||||
$(window).scroll(function () {
|
$(window).scroll(function () {
|
||||||
var s = $(document).scrollTop(),cached = $('.site-header');
|
var s = $(document).scrollTop(),
|
||||||
|
cached = $('.site-header');
|
||||||
if (s == h1) {
|
if (s == h1) {
|
||||||
cached.removeClass('yya');
|
cached.removeClass('yya');
|
||||||
}
|
}
|
||||||
@ -1505,16 +1529,18 @@ var home = location.href,
|
|||||||
$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
|
$body = (window.opera) ? (document.compatMode == "CSS1Compat" ? $('html') : $('body')) : $('html,body');
|
||||||
var load_post_timer;
|
var load_post_timer;
|
||||||
var intersectionObserver = new IntersectionObserver(function (entries) {
|
var intersectionObserver = new IntersectionObserver(function (entries) {
|
||||||
if (entries[0].intersectionRatio <= 0) return;
|
if (entries[0].intersectionRatio <= 0) return;
|
||||||
var page_next = $('#pagination a').attr("href");
|
var page_next = $('#pagination a').attr("href");
|
||||||
var load_key = addComment.I("add_post_time");
|
var load_key = addComment.I("add_post_time");
|
||||||
if(page_next!=undefined && load_key ){
|
if (page_next != undefined && load_key) {
|
||||||
var load_time = addComment.I("add_post_time").title;
|
var load_time = addComment.I("add_post_time").title;
|
||||||
if(load_time !="233"){
|
if (load_time != "233") {
|
||||||
console.log("%c 自动加载时倒计时 %c","background:#9a9da2; color:#ffffff; border-radius:4px;","","",load_time);
|
console.log("%c 自动加载时倒计时 %c", "background:#9a9da2; color:#ffffff; border-radius:4px;", "", "", load_time);
|
||||||
load_post_timer=setTimeout(function(){load_post();},load_time*1000);
|
load_post_timer = setTimeout(function () {
|
||||||
}
|
load_post();
|
||||||
}
|
}, load_time * 1000);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
intersectionObserver.observe(
|
intersectionObserver.observe(
|
||||||
document.querySelector('.footer-device')
|
document.querySelector('.footer-device')
|
||||||
@ -1524,7 +1550,8 @@ var home = location.href,
|
|||||||
load_post();
|
load_post();
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
function load_post() {
|
|
||||||
|
function load_post() {
|
||||||
$('#pagination a').addClass("loading").text("");
|
$('#pagination a').addClass("loading").text("");
|
||||||
$.ajax({
|
$.ajax({
|
||||||
type: "POST",
|
type: "POST",
|
||||||
@ -1539,17 +1566,19 @@ var home = location.href,
|
|||||||
post_list_show_animation();
|
post_list_show_animation();
|
||||||
if (nextHref != undefined) {
|
if (nextHref != undefined) {
|
||||||
$("#pagination a").attr("href", nextHref);
|
$("#pagination a").attr("href", nextHref);
|
||||||
//加载完成上滑
|
//加载完成上滑
|
||||||
var tempScrollTop = $(window).scrollTop();
|
var tempScrollTop = $(window).scrollTop();
|
||||||
$(window).scrollTop(tempScrollTop);
|
$(window).scrollTop(tempScrollTop);
|
||||||
$body.animate({ scrollTop: tempScrollTop + 300 }, 666)
|
$body.animate({
|
||||||
|
scrollTop: tempScrollTop + 300
|
||||||
|
}, 666)
|
||||||
} else {
|
} else {
|
||||||
$("#pagination").html("<span>很高兴你翻到这里,但是真的没有了...</span>");
|
$("#pagination").html("<span>很高兴你翻到这里,但是真的没有了...</span>");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
XCS: function () {
|
XCS: function () {
|
||||||
var __cancel = jQuery('#cancel-comment-reply-link'),
|
var __cancel = jQuery('#cancel-comment-reply-link'),
|
||||||
@ -1748,8 +1777,8 @@ $(function () {
|
|||||||
$(document).pjax('a[target!=_top]', '#page', {
|
$(document).pjax('a[target!=_top]', '#page', {
|
||||||
fragment: '#page',
|
fragment: '#page',
|
||||||
timeout: 8000,
|
timeout: 8000,
|
||||||
}).on('pjax:beforeSend', () => { //离开页面停止播放
|
}).on('pjax:beforeSend', () => { //离开页面停止播放
|
||||||
$('.normal-cover-video').each(function() {
|
$('.normal-cover-video').each(function () {
|
||||||
this.pause();
|
this.pause();
|
||||||
this.src = '';
|
this.src = '';
|
||||||
this.load = '';
|
this.load = '';
|
||||||
@ -1784,7 +1813,7 @@ $(function () {
|
|||||||
if ($('.js-search.is-visible').length > 0) {
|
if ($('.js-search.is-visible').length > 0) {
|
||||||
$('.js-toggle-search').toggleClass('is-active');
|
$('.js-toggle-search').toggleClass('is-active');
|
||||||
$('.js-search').toggleClass('is-visible');
|
$('.js-search').toggleClass('is-visible');
|
||||||
$('html').css('overflow-y','unset');
|
$('html').css('overflow-y', 'unset');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
window.addEventListener('popstate', function (e) {
|
window.addEventListener('popstate', function (e) {
|
||||||
@ -1838,4 +1867,4 @@ if ((isWebkit || isOpera || isIe) && document.getElementById && window.addEventL
|
|||||||
element.focus();
|
element.focus();
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
}
|
}
|
38
options.php
38
options.php
@ -1004,6 +1004,44 @@ function optionsframework_options() {
|
|||||||
'type_3' => __('23 333 Views (french)', 'sakura'),/*23 333 次访问(法式)*/
|
'type_3' => __('23 333 Views (french)', 'sakura'),/*23 333 次访问(法式)*/
|
||||||
'type_4' => __('23k Views (chinese)', 'sakura'),/*23k 次访问(中式)*/
|
'type_4' => __('23k Views (chinese)', 'sakura'),/*23k 次访问(中式)*/
|
||||||
));
|
));
|
||||||
|
|
||||||
|
$options[] = array(
|
||||||
|
'name' => __('Comment image upload API', 'sakura'),/*评论图片上传接口*/
|
||||||
|
'id' => 'img_upload_api',
|
||||||
|
'std' => "imgur",
|
||||||
|
'type' => "radio",
|
||||||
|
'options' => array(
|
||||||
|
'imgur' => __('Imgur (https://imgur.com)', 'sakura'),
|
||||||
|
'smms' => __('SM.MS (https://sm.ms)', 'sakura')
|
||||||
|
));
|
||||||
|
|
||||||
|
$options[] = array(
|
||||||
|
'name' => __('Imgur Client ID', 'sakura'),
|
||||||
|
'desc' => __('Register your application <a href="https://api.imgur.com/oauth2/addclient">here</a>, note we only need the Client ID here.', 'sakura'),
|
||||||
|
'id' => 'imgur_client_id',
|
||||||
|
'std' => '',
|
||||||
|
'type' => 'text');
|
||||||
|
|
||||||
|
$options[] = array(
|
||||||
|
'name' => __('SM.MS Secret Token', 'sakura'),
|
||||||
|
'desc' => __('Register your application <a href="https://sm.ms/home/apitoken">here</a>.', 'sakura'),
|
||||||
|
'id' => 'smms_client_id',
|
||||||
|
'std' => '',
|
||||||
|
'type' => 'text');
|
||||||
|
|
||||||
|
$options[] = array(
|
||||||
|
'name' => __('Comment images proxy', 'sakura'),
|
||||||
|
'desc' => __('A front-ed proxy for the uploaded images. Leave it blank if you do not need.', 'sakura'),
|
||||||
|
'id' => 'cmt_image_proxy',
|
||||||
|
'std' => 'https://images.weserv.nl/?url=',
|
||||||
|
'type' => 'text');
|
||||||
|
|
||||||
|
$options[] = array(
|
||||||
|
'name' => __('Imgur upload proxy', 'sakura'),
|
||||||
|
'desc' => __('A back-ed proxy to upload images. You may set a self hosted proxy with Nginx, following my <a href="https://2heng.xin/2018/06/06/javascript-upload-images-with-imgur-api/">turtal</a>. This feature is mainly for Chinese who cannot access to Imgur due to the GFW. The default and official setting is 【<a href="https://api.imgur.com/3/image/">https://api.imgur.com/3/image/</a>】', 'sakura'),
|
||||||
|
'id' => 'imgur_upload_image_proxy',
|
||||||
|
'std' => 'https://api.imgur.com/3/image/',
|
||||||
|
'type' => 'text');
|
||||||
|
|
||||||
$options[] = array(
|
$options[] = array(
|
||||||
'name' => __('Enable live search', 'sakura'),/*启用实时搜索*/
|
'name' => __('Enable live search', 'sakura'),/*启用实时搜索*/
|
||||||
|
Loading…
Reference in New Issue
Block a user