Skip to content

Instantly share code, notes, and snippets.

@t-ashula
Created April 3, 2017 14:13
Show Gist options
  • Save t-ashula/67efdd0de3cdbd10b9f4a7b0115f30ee to your computer and use it in GitHub Desktop.
Save t-ashula/67efdd0de3cdbd10b9f4a7b0115f30ee to your computer and use it in GitHub Desktop.
from http//sukasuka-anime.com/chara/nopht.html
$(function(){
//シェアボタンを取得
const shareTwitter = document.getElementsByClassName('js-share--twitter'); // ツイートボタンを取得
const shareFacebook = document.getElementsByClassName('js-share--facebook'); // ツイートボタンを取得
const shareLine = document.getElementsByClassName('js-share--line'); // ツイートボタンを取得
// 内容を取得
const url = location.href; // ページURLを取得
const title = document.title; // ページタイトルを取得
const desc = $("meta[name=description]").attr("content"); //ページディスクリプションを取得
const hashtag = ""; // ハッシュタグ(data-hashtags属性)を取得
const related = ""; // おすすめユーザー(data-related属性)を取得
// 内容を合わせる
const twitterHref = (encodeURI(decodeURI('https://twitter.com/intent/tweet?text='+ title + '&url=' + url + '&hashtags=' + hashtag + '&related=' + related)));
const facebookHref = (encodeURI(decodeURI('http://www.facebook.com/sharer.php?u='+ url)));
const lineHref = (encodeURI(decodeURI('http://line.me/R/msg/text/?'+ title + '%0D%0A' + '&url=' + url)));
// 内容を書き換え
$(shareTwitter).attr('href',twitterHref);
$(shareFacebook).attr('href',facebookHref);
$(shareLine).attr('href',lineHref);
// リンクを新規サブウィンドウで表示
$(shareTwitter).click(newWindow);
$(shareFacebook).click(newWindow);
function newWindow(){
const w = 550; //ウィンドウ幅
const h = 450; //ウィンドウ高さ
const x = (screen.width - w) / 2; //x軸中央揃え
const y = (screen.height - h) / 2; //y軸中央揃え
window.open(this.href,null, 'screenX='+x+',screenY='+y+',left='+x+',top='+y+',width='+w+',height='+h);
return false;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment