「MediaWiki:Common.js」の版間の差分

提供:作業療法大百科事典OtWiki
編集の要約なし
編集の要約なし
(同じ利用者による、間の2版が非表示)
1行目: 1行目:
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */
/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */


document.addEventListener('DOMContentLoaded', function() {
const share_url = location.href;
    // 現在のページのURLを取得
const share_hostpath = location.host + location.pathname;
    var currentPageUrl = window.location.href;
const share_title = document.title;


    // Twitterボタンを取得
// facebook
    var twitterButton = document.querySelector('#footer-places-snsbuttonX a');
const share_facebook = document.getElementById("js-share-facebook");
share_facebook.setAttribute(
"href",
"http://www.facebook.com/share.php?u=" + share_url
);


    // URLが正しく取得できたかを確認
// twitter
    if (twitterButton) {
const share_twitter = document.getElementById("js-share-twitter");
        // Twitterのシェア用URLを設定
share_twitter.setAttribute(
        var twitterShareUrl = 'https://twitter.com/intent/tweet?url=' + encodeURIComponent(currentPageUrl) + '&text=' + encodeURIComponent(document.title);
"href",
"https://twitter.com/share?url=" + share_url + "&text=" + share_title
);


        // href属性にURLを設定
// line
        twitterButton.href = twitterShareUrl;
const share_line = document.getElementById("js-share-line");
    } else {
share_line.setAttribute(
        console.error("Twitterボタンが見つかりませんでした。");
"href",
    }
"https://social-plugins.line.me/lineit/share?url=" + share_url
});
);
 
// hatena
const share_hatena = document.getElementById("js-share-hatena");
share_hatena.setAttribute(
"href",
"http://b.hatena.ne.jp/entry/s/" + share_hostpath
);
 
// pocket
const share_pocket = document.getElementById("js-share-pocket");
share_pocket.setAttribute(
"href",
"http://getpocket.com/edit?url=" + share_url
);

2024年5月30日 (木) 21:00時点における版

/* ここにあるすべてのJavaScriptは、すべてのページ読み込みですべての利用者に対して読み込まれます */

const share_url = location.href;
const share_hostpath = location.host + location.pathname;
const share_title = document.title;

// facebook
const share_facebook = document.getElementById("js-share-facebook");
share_facebook.setAttribute(
	"href",
	"http://www.facebook.com/share.php?u=" + share_url
);

// twitter
const share_twitter = document.getElementById("js-share-twitter");
share_twitter.setAttribute(
	"href",
	"https://twitter.com/share?url=" + share_url + "&text=" + share_title
);

// line
const share_line = document.getElementById("js-share-line");
share_line.setAttribute(
	"href",
	"https://social-plugins.line.me/lineit/share?url=" + share_url
);

// hatena
const share_hatena = document.getElementById("js-share-hatena");
share_hatena.setAttribute(
	"href",
	"http://b.hatena.ne.jp/entry/s/" + share_hostpath
);

// pocket
const share_pocket = document.getElementById("js-share-pocket");
share_pocket.setAttribute(
	"href",
	"http://getpocket.com/edit?url=" + share_url
);