const deviceJudge = (function(ua) {
    return {
        sp:
            (ua.indexOf('Android') > 0 && ua.indexOf('Mobile') > 0) ||
            ua.indexOf('iPhone') > 0 ||
            ua.indexOf('iPod') > 0 ||
            ua.indexOf('Windows Phone') > 0,
        tb:
            (ua.indexOf('Android') > 0 && ua.indexOf('Mobile') === -1) ||
            ua.indexOf('iPad') > 0,
        ios:
            ua.indexOf('iPhone') > 0 ||
            ua.indexOf('iPod') > 0 ||
            ua.indexOf('iPad') > 0
    };
})(window.navigator.userAgent);

(function (doc) {
    'use strict';
    let html = doc.documentElement;
    const dataUA = deviceJudge.sp ? 'sp' : deviceJudge.tb ? 'tb' : 'pc';
    const extraReg = new RegExp('(?:&|\\?)(extra=true)(?:&|$)');
    const extraMatchParam = location.search.match(extraReg);
    const dataExtra = extraMatchParam ? true : false;
    const dataWindow = (window != top) ? 'modal' : 'top';

    if (html && html.nodeType === 1) {
        html.setAttribute('data-script-enabled', 'true');
        html.setAttribute('data-ua', dataUA);
        html.setAttribute('data-extra-enabled', dataExtra);
        html.setAttribute('data-window',dataWindow);
    }
    html = null;
}(window.document));
