「Widget:人気ページ」の版間の差分

編集の要約なし
Add table-layout:fixed for mobile fix
 
(4人の利用者による、間の84版が非表示)
1行目: 1行目:
<!DOCTYPE html>
<includeonly>
<html lang="ja">
<html lang="ja">
<head>
<head>
  <!-- Required meta tags -->
  <meta charset="UTF-8">
  <title>chart</title>
  <style>
    #chart_div {
      margin: 0;
      height: 100%;
      min-height: 38em;
      overflow: hidden;
    }


     #chart_div .tab {
     <style>
      margin: 0;
        #chart_div table {
      padding: 0;
            table-layout: fixed;
      display: block;
            width: 100%;
      overflow: hidden;
            border-collapse: collapse;
    }
            border-spacing: 0;
            margin: 1rem 0;
        }


    #chart_div .tab li {
        #chart_div .time {
      display: block;
            width: 3rem;
      float: left;
        }
      width: 50%;
      text-align: center;
      background-color: #aca6e4;
    }


    #chart_div .tab a {
        #chart_div .pageview {
      color: white;
            width: 2.5rem;
    }
        }


    #chart_div .tab a.selected {
        #chart_div td.time {
      font-weight: bold;
            text-align: right;
      cursor: text;
            font-size: 0.8rem;
    }
        }


    #chart_div .tab a.selected:hover {
        #chart_div td.pageview {
      text-decoration: none;
            text-align: center;
    }
            font-size: 0.8rem;
        }


    #chart_div table {
        #chart_div td.page {
      width: 100%;
            text-overflow: ellipsis;
      border-collapse: collapse;
            overflow: hidden;
      border-spacing: 0;
            white-space: nowrap;
      margin: 1rem 0;
        }
    }


    #chart_div .time {
        #chart_div th,
      width: 3rem;
        #chart_div td {
    }
            border: 1px solid #ddd;
        }
       
        #chart_div th {
            text-align: center;
        }


    #chart_div .pageview {
        #chart_div th.selectable {
      width: 2.5rem;
            cursor: pointer;
    }
        }


    #chart_div td.time {
        #chart_div th.selected {
      text-align: right;
            cursor: auto;
      font-size: 0.8rem;
            background-repeat: no-repeat;
    }
            background-position: center right 0.2rem;
        }


    #chart_div td.pageview {
        .page {
      text-align: right;
            overflow: hidden;
      font-size: 0.8rem;
    text-overflow: ellipsis;
    }
    white-space: nowrap;
        }


     #chart_div td.page {
     </style>
      text-overflow: ellipsis;
    <!--Load the AJAX API-->
      max-width: 0;
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
      overflow: hidden;
    <script type="text/javascript">
      white-space: nowrap;
        var period = "daily",
    }
            orderBy = "pageview";
        prepareChart();


    #chart_div th,
        function prepareChart() {
    #chart_div td {
            var sheetName =
      border: 1px solid #ddd;
                period +
    }
                " " +
                (orderBy === "time" ? "longest time spent" : "most viewed");
            var url =
                "https://docs.google.com/spreadsheets/d/1QrIPnTnAaJSoKRy-IcWCoDylC3K8pdbfINNVFs7XEnA/gviz/tq?sheet=" +
                sheetName +
                "&headers=15";


    #chart_div th.selectable {
            google.charts.load("current", {packages: ["corechart"]});
      cursor: pointer;
            google.charts.setOnLoadCallback(drawChart);
    }


    #chart_div th.selected {
            function drawChart() {
      background-image: url("/resources/src/jquery.tablesorter.styles/images/sort_down.png");
                var query = new google.visualization.Query(url);
      cursor: auto;
                query.send(handleQueryResponse);
      background-repeat: no-repeat;
            }
      background-position: center right 0.2rem;
    }


    @media screen and (max-width: 768px) {
            function handleQueryResponse(response) {
      #chart_div {
                var data = response.getDataTable();
        margin: 0;
                var rows = data.getNumberOfRows();
        width: 100%;
                var html = [
        height: 100%;
`<table>
        min-height: 38em;
     <thead bgcolor = #507f50>
        overflow: hidden;
        <tr>
      }
            <th id="header-pageview" class="pageview selectable ${orderBy === "pageview" ? "selected" : ""}">PV</th>
     }
            <th>ページ</th>
  </style>
        </tr>
  <!--Load the AJAX API-->
    </thead>
  <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
     <tbody>
  <script type="text/javascript">
                `];
     var period = "daily",
                for (var i = 0; i < rows; i++) {
      orderBy = "time";
                    try {
    prepareChart();
                        var title = data.getValue(i, 1).replace(" - 宇宙wiki", "");
    function prepareChart() {
                        var pageview = data.getValue(i, 3);
      var sheetName =
                        var url = "/w/" + encodeTitle(title);
        period +
                        var anchor = `<a href="${url}" target="_parent" title="${title}">${title}</a>`;
        " " +
        (orderBy == "time" ? "longest time spent" : "most viewed");
      var url =
        "https://docs.google.com/spreadsheets/d/1niIGejZ1Czrkj07hGDPleVvk9AEBaDtjr55n63GluLw/gviz/tq?sheet=" +
        sheetName +
        "&headers=15";


      google.charts.load("current", { packages: ["corechart"] });
                        html.push(`
      google.charts.setOnLoadCallback(drawChart);
<tr>
    <td class="pageview">${pageview}</td>
    <td class="page" >${anchor}</td>
</tr>
`);
                    } catch (e) {
                        console.log([i, e]);
                    }
                }
                html.push("</tbody></table>");
                document.querySelector("#chart_div").innerHTML = html.join('');


      function drawChart() {
                document
        var query = new google.visualization.Query(url);
                    .getElementById("hourly")
        query.send(handleQueryResponse);
                    .addEventListener("click", function () {
      }
                        if (period === "hourly") return;
                        period = "hourly";
                        prepareChart();
                    });
                document
                    .getElementById("daily")
                    .addEventListener("click", function () {
                        if (period === "daily") return;
                        period = "daily";
                        prepareChart();
                    });
                document
                    .getElementById("header-pageview")
                    .addEventListener("click", function () {
                        if (orderBy === "pageview") return;
                        orderBy = "pageview";
                        prepareChart();
                    });
            }
        }


      function handleQueryResponse(response) {
        function encodeTitle(title) {
        var data = response.getDataTable();
            return title
        var rows = data.getNumberOfRows();
                .split("/")
        var html = [
                .map(function (path) {
          '<ul class="tab">' +
                    return encodeURIComponent(path);
          '<li><a id="hourly" class="' +
                })
          (period == "hourly" ? "selected" : "") +
                .join("/");
          '" href="javascript: void(0);">リアルタイム</a></li>' +
          '<li><a id="daily" class="' +
          (period == "daily" ? "selected" : "") +
          '" href="javascript: void(0);">一日</a></li>' +
          "</ul>" +
          "<table><thead><tr>" +
          '<th id="header-time" class="time selectable ' +
          (orderBy == "time" ? "selected" : "") +
          '">時間</th>' +
          '<th id="header-pageview" class="pageview selectable ' +
          (orderBy == "pageview" ? "selected" : "") +
          '">PV</th>' +
          "<th>ページ</th>" +
          "</tr></thead><tbody>"
        ];
        for (var i = 0; i < rows; i++) {
          try {
            var title = data.getValue(i, 0).replace(" - 宇宙wiki", "");
            var time = Math.round(data.getValue(i, 1) / 60) + "分";
            var pageview = data.getValue(i, 2);
            var url = "/w/" + encodeTitle(title);
            var anchor =
              '<a href="' +
              url +
              '" target="_parent" title="' +
              title +
              '">' +
              title +
              "</a>";
            html.push(
              "<tr>" +
              '<td class="time">' +
              time +
              "</td>" +
              '<td class="pageview">' +
              pageview +
              "</td>" +
              '<td class="page">' +
              anchor +
              "</td>" +
              "</tr>"
            );
          } catch (e) {
            console.log([i, e]);
          }
         }
         }
        html.push("</tbody></table>");
     </script>
        document.querySelector("#chart_div").innerHTML = html.join("\n");
 
        document
          .getElementById("hourly")
          .addEventListener("click", function () {
            if (period == "hourly") return;
            period = "hourly";
            prepareChart();
          });
        document
          .getElementById("daily")
          .addEventListener("click", function () {
            if (period == "daily") return;
            period = "daily";
            prepareChart();
          });
        document
          .getElementById("header-time")
          .addEventListener("click", function () {
            if (orderBy == "time") return;
            orderBy = "time";
            prepareChart();
          });
        document
          .getElementById("header-pageview")
          .addEventListener("click", function () {
            if (orderBy == "pageview") return;
            orderBy = "pageview";
            prepareChart();
          });
      }
     }
 
    function encodeTitle(title) {
      return title
        .split("/")
        .map(function (path) {
          return encodeURIComponent(path);
        })
        .join("/");
    }
  </script>
</head>
</head>
<body>
<body>
  <div id="chart_div"></div>
<div id="chart_div"></div>
</body>
</body>
</html>
</html>
</includeonly>
<noinclude>
{{DEFAULTSORT:}}
</noinclude>

2026年5月28日 (木) 15:08時点における最新版